-1

I have a SELECT command that I used to pull out a single value from my table.

My table (Table_1) is:

enter image description here

So for my new table I want to use the command

SELECT [AMOUNT] 
FROM [TABLE_1] 
WHERE [REDS] = 'Type1'

and so on for each of the types in my new table. So I wanted to use those SELECT commands but I guess for formulas for a column they can only be things like Average or Count or Sum. Is there a way to go about this using the SELECT commands?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
CSharpDev4Evr
  • 535
  • 1
  • 11
  • 35

1 Answers1

2

You're using [REDS] as a field here (implied by the brackets). I am not really sure what you are trying to do based on the rest of your lower question though. Can you re-word your question at all?

I think what you need to do is pivot the data so that your values for [Key] are converted to fields, so it would look like

[Type] [Red] [Greens] [Oranges]
Type1  4     0        0
Type2  0     6        0
Type3  0     0        8

This data could then be put in a temporary table, which you can issue your query to aggregate the data as required.

I can help you with the pivot if this sounds like what you are trying to do?

Stuart

Stuart
  • 281
  • 1
  • 7
  • this is what I am trying to do. So my SELECT would be SELECT [RED] FROM [TABLE_1] WHERE [TYPE] = [TYPE1]. I needed to build a new table with a few of those SELECT commands to create the values. Hope this makes sense. New to using SQL this extensively so not really sure of proper wording or lingo. Thanks – CSharpDev4Evr Nov 20 '13 at 01:03
  • You seem to have a syntax issue here. [TYPE] is your fiend, and TYPE1 is data. So you should use something like SELECT [Key] FROM [TABLE_1] WHERE [TYPE] = 'TYPE1'. This would give you 'REDs' as your result. If this is still not what you are after, then can you please provide what you'd like to see as an example like you did with the input table? Your request is a bit tough to understand I'm sorry. – Stuart Nov 20 '13 at 03:45