| Author |
Topic  |
|
|
dbaz
Starting Member
5 Posts |
Posted - 10/18/2005 : 08:10:22
|
DEAR ALL. I have below table: VID SID 1 1 1 2 1 3 2 1 2 3 2 5 2 6 3 2 3 3 4 5 4 6
First : select VID, Count(*) AS CountOfSID from Table1 group by VID Result : VID CountOFSID 1 3 2 4 3 2 4 2
Now From this result I want to get below result wtih query: select CountOFSID, count(*)As F FROM "Result" GROUP BY CountOFSID Result: CountOFSID F 2 2 3 1 4 1
------- I can do if with Oracle with one sql select:
select CountOFSID, count(*)As F FROM (select VID, Count(*) AS CountOfSID from Table1 group by VID ) group by CountOFSID
Can it be coverted to SQL as one select statement?
Thanks advance.
|
|
|
robvolk
Most Valuable Yak
USA
15559 Posts |
Posted - 10/18/2005 : 08:11:14
|
Ummmm, yeah, just paste it into Query Analyzer and run it.
Actually, you do have to make one small change:
select CountOFSID, count(*)As F FROM (select VID, Count(*) AS CountOfSID from Table1 group by VID ) AS myQuery group by CountOFSID
When SELECTing from a subquery in SQL Server, the subquery must be aliased (in blue). |
 |
|
| |
Topic  |
|
|
|