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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Who knows a solution for this query

Status
Not open for further replies.

michelleqw

Programmer
Jan 4, 2004
120
DE
Dear sqlserver users,

We are trying to get the count of the percentages per shopid

For example:

shopid discount_percentage
1 50
1 10
1 10
1 10
1 50
2 10
3 50
4 30

Result:

shopid 10_perc 50_perc
1 4 2
2 1 0
3 0 1
4 0 0

Knows someone how to do this?

Nice regards,

Michelle.
 
Code:
select shopid,
sum(case when discount_percentage = 10 then 1 else 0 end),
sum(case when discount_percentage = 50 then 1 else 0 end)
from t
group by shopid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top