Friday, February 24, 2012

group by

I've created a table containing columns date, cost, orders etc. I want to
write a query group by the month part of the date. Is it possible to write
it. if yes how. Any suggestion would be greatly appreciated.
regards
shineSELECT AVG(cost), DATEPART(mm, datecol)
FROM tbl
GROUP BY DATEPART(mm, datecol)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"shine" <shine@.discussions.microsoft.com> wrote in message
news:F792B5DB-98C6-48C3-B85C-EE43E2915567@.microsoft.com...
> I've created a table containing columns date, cost, orders etc. I want to
> write a query group by the month part of the date. Is it possible to write
> it. if yes how. Any suggestion would be greatly appreciated.
> regards
> shine|||Example:
use northwind
go
select month(orderdate) as month_number, count(*) as month_cnt
from dbo.orders
group by month(orderdate);
AMB
"shine" wrote:

> I've created a table containing columns date, cost, orders etc. I want to
> write a query group by the month part of the date. Is it possible to write
> it. if yes how. Any suggestion would be greatly appreciated.
> regards
> shine

No comments:

Post a Comment