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!

HELP WITH QUERY

Status
Not open for further replies.

spiff2002

IS-IT--Management
Jan 31, 2003
40
I'm trying to create a query where I have a table similar to this

region brand cases_sold
reg1 brand1 20
reg1 brand2 30
reg1 brand3 25
reg2 brand3 23
reg2 brand1 25

I need to add the total of certain brands and put them together in one label for both brands (in this case brand1 and brand2) and get an output like this

reg1 brand1/brand2 50
reg1 brand3 25
reg2 brand3 23
reg2 brand1/brand2 25

can somebody help me with this??
 

Code:
select region,brand,sum(case_sold) from (
select case when brand in ('brand1','brand2') then 
'brand1/brand2' else brand end as brand, region, case_sold
from t ) dt
group by region,brand
order by region,brand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top