一个表shop含三个属性:article(商品),dealer(交易者),price(价格)
现在“对每种商品,找出最贵的价格的交易者”答案如下:select article,dealer,price
          from shop s1
          where price=(select max(s2.price)
                       from shop s2
                       where s1.article=s2.atricle)
我验证了一下结果是对的,但是我不太明白,请哪位高手讲解一下。

解决方案 »

  1.   

    用这句更简单
    select * from shop where price=(select max(price) from shop)
      

  2.   

    上面的答案不正确请不要看了, 分析下你的解答
    quto:select article,dealer,price
              from shop s1
              where price=(select max(s2.price)
                           from shop s2
                           where s1.article=s2.article)
    其中 where s1.article=s2.article 相当于对article进行分组 然后找出分组中price最大的那项