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: TurkBear <noone_at_nowhere.com>
Date: Thu, 29 Mar 2001 08:32:53 -0600
Message-ID: <gnh6ct40bud2ftfvlqeqink4kaglr2gbba@4ax.com>

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;

Ole Christian <olecl_at_stud.idb.hist.no> wrote:

>This sentence works perfectly:
>select field_name, sum(numbers) as numbers
>from topten
>group by field_name
>order by numbers desc
>
>While this sentence:
>select field_name, sum(numbers) as numbers
>from topten
>group by field_name, date_field
>having months_between(sysdate,date_field)<1
>order by numbers desc;
>
>The first sentence summarises the "numbers" for each field_name and then
>lists them out like this:
>field 1 123
>field 3 45
>field 2 23
>
>While sentence two which should do the same, just within a certain
>daterange like months, weeks, years, lists this double double shit:
>field 1 100
>field 3 14
>field 1 23
>field 2 20
>field 2 3
>
>How can I go round this?
>
>Ole C.
>
  Received on Thu Mar 29 2001 - 08:32:53 CST

Original text of this message

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