不是我自己不想动脑, 是因为我不太熟悉MAX集函数的用法一个表:
MID   MPID   AMOUNT   PRICE其中MID和MPID共同作为主码. 所以对应一个MID, 可能存在几个元组(行).我希望通过MID, 找到PRICE值最大的元组(行), 怎么解决这个问题?多谢!

解决方案 »

  1.   

    每太明白什么叫主码sql->select Mid,Max(PRICE) from tab1 group by mid
      

  2.   

    select max(price) from table where mid=@mid
      

  3.   

    select max(PRICE) from table1 group by MID;
      

  4.   

    select MID,MPID,AMOUNT,max(price) as maxprice from table group by MID where MID=@mid
      

  5.   

    SELECT * FROM T1  WHERE MID  = @mid AND 
    MPID = (SELECT MAX(PRICE) FROM T1 WHERE MID   =  @mid  GROUP BY MID )
      

  6.   

    select top 1 * from table where MID  = @mid order by PRICE desc
      

  7.   

    select MID,MPID   from t as t1 where not exists(select 1 from t as t2 
    where t1.mid = t2.mid and t2.mpid>t1.mpid)
      

  8.   

    create table t(MID int,MPID int,Price int)
    insert t select 1,1,10
    union all select 1,2,2
    union all select 1,3,12
    union all select 2,1,14declare @mid int
    set @mid=1select max(price) [maxPrice] from t group by mid having mid=@middrop table t
    /*
    maxPrice    
    ----------- 
    12
    */