一道oracle试题

 做不出来时感觉好难啊,思路千千万,就是没想到用 Order by 和 rownum  。题目如下:

有下面三个表:
商品product(商品号productid,商品名productname,单价unitprice,商品类别category,供应商provider);
顾客customer(顾客号customerid,姓名name,住址location);
购买purcase(顾客号customerid,商品号productid,购买数量quantity);
要求:

1. 请建表(自学完成),然后插入以下记录
商品(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;   select provider from product p where category='牙膏' and p.productid group by provider
     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;)

问题:求牙膏卖出数量最多的供应商 (答案见下方)

select provider from(select provider,sum(quantity) as 数量 from product,purcase where product.PRODUCTID=purcase.productid
and product.category='牙膏' group by provider order by 数量 desc) where rownum=1;
原文地址:https://www.cnblogs.com/zwl24/p/2356790.html