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 |
mattashfield
Starting Member
2 Posts |
Posted - 2010-12-15 : 11:47:34
|
Hi, Hope someone can help here.I have some data (sample)id, location001,UK002,US003,Canada004,US005,EnglandUKI want to do a COUNT on the location field but combine US and Canada into a single result and UK and EnglandUK into a single result. i expect my result set to look something like:Location,MyCountUK, 2US,3can someone help me here? |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-12-15 : 12:31:47
|
[code]SELECT CASE WHEN location in ('US', 'CANADA') THEN 'US' WHEN location in ('UK', 'EnglandUK') THEN 'UK' END as location, Count(id) as myCountFROM myTableGROUP BY CASE WHEN location in ('US', 'CANADA') THEN 'US' WHEN location in ('UK', 'EnglandUK') THEN 'UK' END[/code] |
 |
|
|
|
|
|
|