Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

group by question

Status
Not open for further replies.

Ofina

Technical User
Feb 25, 2004
156
US
Sample table
Order field1 field2 field3 Cost
123 Y ABC BCD $2
123 Y ABC ABC $5

Say I have a select statement containing:
case field1
when 'Y' then field2
else field3
end as 'Supplier'

This will result in displaying 'ABC' in the Supplier field correctly.

However, there is a group by statement involved. It wants me to group by both field2 and field3 because they are both in the select statement. But, I would like to group by the result of my case statement. In the example above, I would like:
Order Supplier Cost
123 ABC $7

Does that make any sense?
 
Actually I just tried putting the entire case statement in my group by and it seems to be fine.

Any reason I shouldn't do that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top