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

Home -> Community -> Mailing Lists -> Oracle-L -> SQL Question - Sum with group by

SQL Question - Sum with group by

From: Lucia DeMeester <ldemeester_at_nm2.com>
Date: Thu, 20 Jul 2000 18:41:32 -0700
Message-Id: <10564.112602@fatcity.com>


I have trouble to create a view that will sum a quantity field from a joined table by sku and year and month (YYYYMM). But also display the sku, summed quantity, MM, and YYYY. The ouput of the view is going to write to an inventory table. Sample output: VA013000, 05, 2000, 50 One record per each YYYYMM for each sku.)

If I use the following script, it generates detail quantity for each sku. The quantity is not summaried by the YYYYMM. If I use group by i.sku, to_char(o.order_date,'YYYYMM') then I got error.

create or replace view month_qty_sum_by_sku as select i.sku, to_char(o.order_date, 'MM') as month, to_char(o.order_date, 'YYYY') as year
,sum(i.quantity) as qty
from items i, orders o where
i.order_id = o.order_id and (o.status=5 or o.status=7 or (o.status=16 and i.printed=1)) and
 (o.store_id = 'V')
group by i.sku, o.order_date;

I did try to define a new yymm column and try to group by sku and yymm column and it did not work.

Any one has done this sort of SQL? Received on Thu Jul 20 2000 - 20:41:32 CDT

Original text of this message

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