[原] 求商品最高和最低报价的SQL题(图解)

[原题-- 取自CSDN]

t_product

----------------------------------------------------------

productid           商品       int

productname    商品名称       varchar 50

 

t_sale

----------------------------------------------------------

saleid                 记录编                                              int

productid          价商品号(与product关联)    int

seller                  价商店名称                                              varchar 50

price                   价格                                                              float

为了方便,使用Access创建数据库(因为是外包工,所以用的日文的office,非亲日!!)






最高价SQL语句如下:
SELECT
    t.productid,
    t.productname, 
    s.seller, 
    s.price
FROM
    t_sale s,
    t_product t
WHERE 
    s.price in
        (select max(s.price) from t_sale s GROUP BY s.productid)
AND
    t.productid=s.productid;

运行结果:


最低价SQL语句如下:
SELECT
    t.productid,
    t.productname, 
    s.seller, 
    s.price
FROM
    t_sale s,
    t_product t
WHERE 
    s.price in
        (select min(s.price) from t_sale s GROUP BY s.productid)
AND
    t.productid=s.productid;


运行结果:


高手飘过,呵呵 :-)

posted @ 2007-02-19 16:15  temptation  阅读(872)  评论(0编辑  收藏  举报