a表
批发商ID 批发商名称
----------
1     甲
2     乙
3     丙b表
水果 批发商ID 价格
----------
苹果  1    5
梨   2    3
苹果  3    4.8
苹果  2    4.5
梨   1    2.8
梨   3    2.9
苹果  2    4.6
梨   3    2.9
求:(假设“登录用户”是甲批发商,批发商ID是自增型,不是固定的),数据结果如下
价格(最高) 是指其他批商,不包括登录用户(甲)
价格(最低) 是指其他批商,不包括登录用户(甲)水果  价格(本批发商) 价格(最高) 价格(最低)
--------------------------
苹果   5          5     4.5
梨    2.8         3     2.9如果解答正确,这个贴子也麻烦你只需您回答一下。分一块给。谢谢http://community.csdn.net/Expert/topic/4565/4565967.xml?temp=.2044184

解决方案 »

  1.   

    select 水果,价格,(select max(价格) from b tt where tt.水果=t.水果 and 批发商ID<>1),
    (select min(价格) from b tt where tt.水果=t.水果 and 批发商ID<>1)
     from b t where 批发商ID = 1;
      

  2.   

    select b.水果, b.价格 as "价格(本批发商)"
    , (select max(价格) as "价格(最高)" from b b2 where b2.水果=b.水果 and b2.批发商ID<>b.批发商ID)
    , (select min(价格) as "价格(最低)" from b b2 where b2.水果=b.水果 and b2.批发商ID<>b.批发商ID)
    from b where b.批发商ID=:批发商ID
      

  3.   

    请 QwithoutA(爱提问题的废柴) 到该贴子
    http://community.csdn.net/Expert/topic/4565/4565967.xml?temp=.2044184
    解答一下,两个贴子一起给分