Board index » delphi » SQL Statement month grouping

SQL Statement month grouping

Hi,

I got sales numbers for a whole year and now i need those counted and
grouped per month for different items.
How do i do this?  Is there some sort of group by month function?

each record is this:  ID, item, quantity, datesold

So i need to get all quantitity added up for like item number 5544 and then
grouped per month.

Thanks in advance,

Stijn Verrept.

 

Re:SQL Statement month grouping


Look up EXTRACT and GROUP BY functions in the online help. You will
probably need something like:
SELECT item, SUM(quantity), mm FROM
(SELECT item, quantity, EXTRACT(month FROM datesold) AS mm FROM
tablename)
GROUP BY mm

HTH,
Dan

On Mon, 10 Sep 2001 18:38:13 +0200, "Stijn Verrept"

Quote
<sverr...@NO-SPAM.vub.ac.be> wrote:
>Hi,

>I got sales numbers for a whole year and now i need those counted and
>grouped per month for different items.
>How do i do this?  Is there some sort of group by month function?

>each record is this:  ID, item, quantity, datesold

>So i need to get all quantitity added up for like item number 5544 and then
>grouped per month.

>Thanks in advance,

>Stijn Verrept.

--
Dan Brennand
CMDC systems, inc.
Configuration Management and Document Control:
visit us at www.cmdcsystems.com
[SPAM block: change at to @ in my e-mail address]

Re:SQL Statement month grouping


This is a really slow query. Why not use:

SELECT item, EXTRACT(MONTH FROM datesold) AS mm, SUM(quantity)
FROM tablename
GROUP BY item, EXTRACT(MONTH FROM datesold)

Quote
"Dan Brennand" <D...@CMDCsystems.com> wrote in message

news:3b9d33f3.157805067@news.dimensional.com...
Quote
> Look up EXTRACT and GROUP BY functions in the online help. You will
> probably need something like:
> SELECT item, SUM(quantity), mm FROM
> (SELECT item, quantity, EXTRACT(month FROM datesold) AS mm FROM
> tablename)
> GROUP BY mm

> HTH,
> Dan

> On Mon, 10 Sep 2001 18:38:13 +0200, "Stijn Verrept"
> <sverr...@NO-SPAM.vub.ac.be> wrote:

> >Hi,

> >I got sales numbers for a whole year and now i need those counted and
> >grouped per month for different items.
> >How do i do this?  Is there some sort of group by month function?

> >each record is this:  ID, item, quantity, datesold

> >So i need to get all quantitity added up for like item number 5544 and
then
> >grouped per month.

> >Thanks in advance,

> >Stijn Verrept.

> --
> Dan Brennand
> CMDC systems, inc.
> Configuration Management and Document Control:
> visit us at www.cmdcsystems.com
> [SPAM block: change at to @ in my e-mail address]

Other Threads