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 |
|
madhulatha_b
Starting Member
22 Posts |
Posted - 2004-10-01 : 04:18:47
|
| Hi, I need to write a query to get the number of rows of a category as well total number of rows in that table in a single row. For ex table contains 3 categories like cat1,cat2,cat3. Cat1 contains 2 rows, cat2 contains 3 and cat3 contains 4. The result should be in single rowResult--------2,9Can any body help me to get this result |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2004-10-01 : 04:51:01
|
| how did you get 2? |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2004-10-01 : 05:07:37
|
| show more detailed sample data...and matching expected results....the description given is too vague....... |
 |
|
|
madhulatha_b
Starting Member
22 Posts |
Posted - 2004-10-01 : 05:09:30
|
| 2 is total number of Cat1 rows9 is total number of rows in tableThat table contains 2 rows with cat1, 3 rows with cat2 and 4 rows with cat3 |
 |
|
|
Shurgenz
Yak Posting Veteran
51 Posts |
Posted - 2004-10-01 : 05:10:38
|
| by other words: 2-rows of cat1, 9-total rows of table. Correct? |
 |
|
|
Shurgenz
Yak Posting Veteran
51 Posts |
Posted - 2004-10-01 : 05:12:07
|
| select sum(case when f=cat1 then 1 else 0 end), count(*) from tt-your tablef-cat field |
 |
|
|
madhulatha_b
Starting Member
22 Posts |
Posted - 2004-10-01 : 05:20:10
|
| Suppose there is a table called CLASS with a column called NAME withdata as below,NAME---------CARCARSCOOTERSCOOTERAEROPLANEBIKENow I want with a single SQL query the number of entries with valueSCOOTER and the total number of entries.i.e., I expect to get the values 2,6How do I write such a query?Hope I am clear. |
 |
|
|
Shurgenz
Yak Posting Veteran
51 Posts |
Posted - 2004-10-01 : 05:21:32
|
| select sum(case when name='scooter' then 1 else 0 end), count(*) from class |
 |
|
|
madhulatha_b
Starting Member
22 Posts |
Posted - 2004-10-01 : 05:38:31
|
| Thanks for your reply. It's working |
 |
|
|
|
|
|
|
|