Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Translate SQL query From Oracle To SQL Server
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dbaz
Starting Member

5 Posts

Posted - 10/18/2005 :  08:10:22  Show Profile  Reply with Quote
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
15732 Posts

Posted - 10/18/2005 :  08:11:14  Show Profile  Visit robvolk's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000