MYSQL查询一张表如何查询出最新信息

MYSQL查询一张表如何查询出最新信息,第1张

假设表名是D, 正确答案如下:

select t2.eid, t2.ename, t2.yearmonth

from D t2

join

(

select t1.eid, max(t1.yearmonth) as yearmonth

from D t1

group by t1.eid

) t3

on t2.eid = t3.eid and t2.yearmonth = t3.yearmonth

运行通过后请采纳,谢谢!

你好!

你写的确实有点复杂!

你可以分两步:

1 . 获取每个人每个学科的最新考试成绩

select b.name,b.class,b.score from score b,

(select a.name,a.class,max(a.time) tims from score a group by a.name,a.class) a

where b.name = a.name

  and a.class = b.class

  and a.tims = b.time

2 . 进行行专列 *** 作

对上面的数据进行行列转化 *** 作,比较常见了!

欢迎追问,望采纳

先排序 再 用 group by 取

假设 table xxx

select * from

(select * from xxx order by time desc ) a

group by type

order by type


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8635148.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-19
下一篇 2023-04-19

发表评论

登录后才能评论

评论列表(0条)

保存