现有一个商店的数据库,记录顾客及其购物情况,由下面三个表组成:
商品product(商品号productid,商品名productname,单价unitprice,商品类别category,供应商provider);
顾客customer(顾客号customerid,姓名name,住址location);
购买purcase(顾客号customerid,商品号productid,购买数量quantity);往表中插入数据:
商品(M01,佳洁士,8.00,牙膏,宝洁;
      M02,高露洁,6.50,牙膏,高露洁;
      M03,洁诺,5.00,牙膏,联合利华;
      M04,舒肤佳,3.00,香皂,宝洁;
      M05,夏士莲,5.00,香皂,联合利华;
      M06,雕牌,2.50,洗衣粉,纳爱斯
      M07,中华,3.50,牙膏,联合利华;
      M08,汰渍,3.00,洗衣粉,宝洁;
      M09,碧浪,4.00,洗衣粉,宝洁;)
顾客(C01,Dennis,海淀;
      C02,John,朝阳;
      C03,Tom,东城;
      C04,Jenny,东城;
      C05,Rick,西城;) 
购买(C01,M01,3;     
     C01,M05,2;
     C01,M08,2;     
     C02,M02,5;
     C02,M06,4;     
     C03,M01,1;
     C03,M05,1;     
     C03,M06,3;
     C03,M08,1;     
     C04,M03,7;
     C04,M04,3;     
     C05,M06,2;
     C05,M07,8;(2)求购买的商品包含了顾客"Dennis"所购买的所有商品的顾客(姓名);
(3)求牙膏卖出数量最多的供应商
4 将所有的牙膏商品单价增加10%。
5 删除从未被购买的商品记录。这两个查找怎么查,我查了半天,老是语法错误。 - -

解决方案 »

  1.   

    (2)求购买的商品包含了顾客"Dennis"所购买的所有商品的顾客(姓名);select *
    from customer c
    where not exists (
    select 1 from customer a,purcase b 
    where a.customerid=b.customerid 
    and a.name='Dennis' 
    and b.productid not in(
    select productid from purcase where customerid=c.customerid
    )
    );(3)求牙膏卖出数量最多的供应商
    select a.provider,sum(b.quantity)
    from product a ,purcase b
    where a.productid=b.productid
    and a.category='牙膏'
    order by sum(b.quantity) desc
      

  2.   

    第三个好像要group by provider 吧。
    第二个有问题。
      

  3.   


    (2)支持
    (3)革命还没有结束:
    select provider from
    (select a.provider,sum(b.quantity)
    from product a ,purcase b
    where a.productid=b.productid
    and a.category='牙膏'
    order by sum(b.quantity) desc ) t where rownum<2
      

  4.   


    (2)求购买的商品包含了顾客"Dennis"所购买的所有商品的顾客(姓名); 
    同1楼(3)求牙膏卖出数量最多的供应商 
    最多的供应商可能有多个
    select a.provider, sum(b.quantity) from purcase a, product b 
           where a.productid=b.productid and b.category='牙膏' 
             group by a.provider 
             having sum(b.quantity) = (select sum(b.quantity) from purcase a, product b 
                                           where a.productid=b.productid and b.category='牙膏' 
                                           group by a.provider where rownum <2);4 将所有的牙膏商品单价增加10%。 
    update product set unitprice=unitprice*1.1 where category='牙膏;5 删除从未被购买的商品记录。
    delete from product where not exists (select 1 from purcase where product.productid=purcase.productid);
      

  5.   

    谢谢。 综合了你们的。
    (3)求牙膏卖出数量最多的供应商。select provider from(select a.provider,sum(quantity) s from product a,purcase b where a.productid=b.productid and a.category='牙膏' group by a.provider order by s desc) where rownum<2;