Date parsing

M

Minnow

I have a table called t, it has three fields called CustomerID, DateOrdered,
QuantityOrdered.

Now I want to know how many items ordered totally in each month.

How to acheive this?

Thanks.
 
O

Ofer

Total per Year,Month

SELECT Year([DateOrdered]) AS MyYear, Month([DateOrdered]) AS MyMonth,
Sum(t.QuantityOrdered) AS SumOfQuantityOrdered
FROM t
GROUP BY Year([DateOrdered]), Month([DateOrdered])
ORDER BY Year([DateOrdered]), Month([DateOrdered])
===============================================
If you want per Month regardless which year, then remove the Year
===============================================
Total per Year,Month, customer

SELECT Year([DateOrdered]) AS MyYear, Month([DateOrdered]) AS MyMonth,
t.CustomerID, Sum(t.QuantityOrdered) AS SumOfQuantityOrdered
FROM t
GROUP BY Year([DateOrdered]), Month([DateOrdered]), t.CustomerID
ORDER BY Year([DateOrdered]), Month([DateOrdered])
 
Top