SSISO Community

시소당

8. 특정 품종에 대한 총 판매수량과 금액을 구하라.

Select  sum(sale_amt)  as  total_sale_qty,
                    sum(sale_amt*a.unit_price)  as  total_sale_amt
From  product  a,  sale  b
Where  a.prod_no  =  b.prod_no
And  a.prod_class  in  (‘Foods’,  Furniture’)
And  b.saledate  between  ‘19950101’  and  ‘19950331’

(개선안)
select  sum(v.total_qty)  as  total_sale_qty,
                      sum(v.total_qty*a.unit_price)  as  total_sale_amt
from  (select  prod_no,  sum(sale_amt)  as  total_qty
                    from  sale
                    where  saledate  between  ‘19950101’  and  ‘19950331’
                    group  by  prod_no)  v,  product  a
where  a.prod_no  =  v.prod_no
      and  a.prod_class  in  (‘Foods’,  Furniture’)

1021 view

4.0 stars