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
 General SQL Server Forums
 New to SQL Server Programming
 Count on results of nested query

Author  Topic 

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-09-03 : 22:32:45
I have a complex query that returns something like
Customer ItemsInOrder
Jack 10
Jack 12
Ben 6

If the table already existed -I would use
quote:
Select Customer,Count(ItemsInOder) as NumOrders
from TableA Group By Customer

To get count of Number of Orders for Jack & Ben


However in this case I dont understand how to wrap this structure
around the query that's returning the results

Select Customer,Count(ItemsInOder) as NumOrders
from [Select .... group by ]
Group By Customer

Ideas ??

Thanks



andrewcw

andrewcw
Posting Yak Master

133 Posts

Posted - 2009-09-03 : 22:59:29
OK I think I got an idea from someone elses question

Select D.Customer,Count(ItemsInOder) as NumOrders
from [Select .... group by ] as D
Group By Customer

andrewcw
Go to Top of Page
   

- Advertisement -