用navicat premium怎么查詢出每科成績第一名的學生姓名。
uj5u.com熱心網友回復:
可以查詢出來的uj5u.com熱心網友回復:
你會熟練使用mySQL嘛,uj5u.com熱心網友回復:
會的,有什么問題的話可以+五把而要五兒其三絲
uj5u.com熱心網友回復:
-- 例子如下:
-- 見表
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/69886.html
標籤:MySQL
