Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: SUM and GROUP BY...

Re: SUM and GROUP BY...

From: Niall Litchfield <n-litchfield_at_audit-commission.gov.uk>
Date: Mon, 2 Apr 2001 11:01:49 +0100
Message-ID: <3ac84e11$0$15028$ed9e5944@reading.news.pipex.net>

I believe that you have your where clause in the wrong place

i.e.

select field_name, sum(numbers) as numbers from topten
where months_between(sysdate,date_field)<1 group by field_name
order by numbers desc;

>

"Ole Christian" <olecl_at_stud.idb.hist.no> wrote in message news:3AC847EB.421E5FE6_at_stud.idb.hist.no...
> TurkBear wrote:
>
> > You are grouping by a field that is not in your output, but the grouping
> > remains..that is why it appears to be doubled - it is one sum for each
> > field_name,date_field combination value;
> >
> > Try,
> > select field_name, sum(numbers) as numbers
> > from topten
> > group by field_name
> > where months_between(sysdate,date_field)<1
> > order by numbers desc;
>
> Well, I've tried that that Turkbear. But then the date_field is "not a
 GROUP
> BY function". Which means I cannot use it in the line :
> where months_between(sysdate,date_field)<1
>
> Any other suggestions?
>
> Ole C.
>
>
Received on Mon Apr 02 2001 - 05:01:49 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US