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 |
|
ymamalis
Starting Member
42 Posts |
Posted - 2009-12-13 : 12:31:17
|
| Hello everybody, i have a query that calculates a field named ss (it counts the days difference between 2 days) how can i take results grouped in a range of days , i mean i would like to count how many records do i have with ss column between 0-10 , 11-40 , 41-100 e.t.c.Can you please help me?Wish result TablessCount Range34 1-1078 11-40132 41-1000 |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2009-12-13 : 13:22:05
|
| [code]select case when ss between 1 and 10 then '1-10' when ss between 11 and 40 then '11-40' when ss between 41 and 1000 then '41-1000' end as range, count(*) as ssCountfrom yourtablegroup by case when ss between 1 and 10 then '1-10' when ss between 11 and 40 then '11-40' when ss between 41 and 1000 then '41-1000' end[/code] |
 |
|
|
|
|
|