Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
usafelix
Posting Yak Master
165 Posts |
Posted - 2014-11-16 : 22:45:21
|
I want to group by different sales amount range by each shop in below . How to write this sql query ?select count(sales_memo),sum(salesamount) from salesheader where shopcode like '%0%' and group by a<100,b<200,c<400,d<800, z total ----------Please help to edit the above of sql query. shop y A<$100 450B<$200 50C<$400 30D<$800 20Z total $550 Shop xA<100 200B<200 20C<400 10D<800 10z total $240--- end |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-11-17 : 09:16:16
|
Try a group by clause with a case expression:select count(sales_memo),sum(salesamount) from salesheader where shopcode like '%0%'group by case when a < 100 then 1 when a < 200 then 2 ...end |
|
|
|
|
|