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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Translate SQL query From Oracle To SQL Server

Author  Topic 

dbaz
Starting Member

5 Posts

Posted - 2005-10-18 : 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

15732 Posts

Posted - 2005-10-18 : 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).
Go to Top of Page
   

- Advertisement -