请教一个sql查询语句

DishJi 2018-02-26 04:30:13
id user score do_time
1 a 1 1
2 a 3 1
3 a 3 3
4 b 0 1
5 b 4 4
6 b 4 1


需求是 查询每个用户的最好成绩,当score一样时,取dotime时间最小的记录



...全文
873 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
momoxiangnile 2018-03-22
  • 打赏
  • 举报
回复
select user, max(score),do_time from test_gyy GROUP BY `user` ORDER BY do_time desc
ZXYperseverance 2018-03-13
  • 打赏
  • 举报
回复
SELECT ID,USER,SCORE,DO_TIME FROM (SELECT ID,USER,SCORE,DO_TIME FROM SCORE ORDER BY SCORE DESC,DO_TIME ASC) GROUP BY USER 这个是最简单的写法。
qq_33052575 2018-03-06
  • 打赏
  • 举报
回复
select t.* from (select * from mytable order by score desc, do_time asc) t group by t.user
qq_37358669 2018-03-01
  • 打赏
  • 举报
回复
select user,max(score)as score,min(do_time)as do_time from a group by `user`
rucypli 2018-02-27
  • 打赏
  • 举报
回复
分两步 第一步 取相同用户,分数一样的时间最大 create table test select user,score,max(do_time) from tb group by user,score; 第二部取相同用户分数大的 select * from test A where not exists (select 1 from test B where A.user=B.user and A.score<B.score);
DishJi 2018-02-26
  • 打赏
  • 举报
回复
来个大神解决一下吧,万分感谢

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧