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 2005 Forums
 Transact-SQL (2005)
 2 Aggregation at the same query

Author  Topic 

mayaaa
Starting Member

15 Posts

Posted - 2009-04-01 : 02:25:03
Hey all :)

I'm a begginer at SQL so I would appreciate your help very much.
This is my query:

SELECT Z.*
FROM
(SELECT RowNumber = ROW_NUMBER() OVER (PARTITION BY c.Center ORDER BY [Date] DESC)
,QuarterDesc,
MonthDesc,
c.Center,
count(X) as X,
count(Y) as Y,
count(*) as ALL
from
dbo.tablea a,
dbo.tableb b,
dbo.tablec c
where a.[Date]=b.[Date]
and b.Center=c.Center
GROUP BY
QuarterDesc,
MonthDesc,
c.Center) Z
WHERE Z.RowNumber <= 4
order by Z.Center,Z.RowNumber

I need to also be able to sum X and Y at the same query.

Thank you very much for your assistance!

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-04-01 : 03:50:13
Please post some sample data & desired output.

Select Z.*,sum(X)...
Go to Top of Page
   

- Advertisement -