June 22nd, 2003, 10:02 AM
-
GROUP BY question
I have a relation called Orders with the following attributes:
OrderId, total_price, date, customerId.
Where OrderId is the primary key and customerId a foreign key referencing another relation. Does anybody know how can I group the tuples of this relation acording to year and month only? If a say for example something like "GROUP BY date" my data will be grouped by year, month and day. I am only looking for the first two.
Thanks in advance
June 22nd, 2003, 10:44 AM
-
Code:
select y,m,count(*)
from (select extract(year from date) as y,
extract(month from date)
from orders) as dt
group by y,m
June 22nd, 2003, 10:50 AM
-
Thanks I'll give it a try