Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: SUM and GROUP BY...
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