KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to write a query to count the number of records based on a number of different ranges. I have success with using union , but I feel there is a better way to do it. Here is what I've done: select count(col1) as range1 from tbl1 where col1 <= 15000 union select count(col1) as range2 from tbl1 where col1 > 15001 and col1 <= 30000 union select count(col1) as range3 from tbl1 where col1 > 30001 and col1 <= 45000 etc... I am using sql server 2008. Like I stated above, I'm positive there is a better way to do this, maybe something like this: sql count , EDIT: Yes, the database is sql 2008, and the answers below work exactly as needed. I forgot to mention that I'm actually reading a JSON file that has been serialized via coldfusion serializeJSON . So in the db, everything below worked perfectly, but coldfusion query of queries doesn't support the CASE statement, or it doesn't appear to.
Tags (comma-separated)
Save Edits
Cancel