用navicat premium怎么查询出每科成绩第一名的学生姓名。

解决方案 »

  1.   

    你会熟练使用mySQL嘛,
      

  2.   


    -- 例子如下:-- 见表
    create table t (date varchar(10) , id varchar(10) , high int, weight int)-- 插入数据
    insert into t
          select '2019-03-11','小王', 170 ,62
    union select '2019-03-11','小张', 171 ,63
    union select '2019-03-11','小李', 172 ,64
    union select '2019-02-15','小王', 170 ,63
    union select '2019-02-15','小张', 171 ,63
    union select '2019-02-15','小李', 172 ,64
    union select '2019-01-21','小王', 170 ,64
    union select '2019-01-21','小张', 171 ,62
    union select '2019-01-21','小李', 172 ,64
    union select '2019-01-01','小王', 170 ,62
    union select '2019-01-01','小张', 171 ,67
    union select '2019-01-01','小李', 172 ,64-- 查询
    select * from (
    select @rowid := if(@rank = id  , @rowid + 1 , 1 ) newid , date ,id ,high ,weight , @rank := id flag
    from t , (select @rowid := 0 , @rank := '') a 
    order by id , date desc ) t 
    where newid = 1