mysql group by 批量获取最后的数据
http://www.forasp.cn/ 2021/12/23 19:24:16 点击:不统计
mysql groupy 批量获取最后的数据
1.首先获取最后的数据,先获取id
select max(chapterid) from xx_article_chapter GROUP BY articleid
如果获取第一条数 则需要先进行order 一下
select min(chapterid),articleid from xx_article_chapter GROUP BY articleid
2. 获取对应id后在进行查询
select * from xx_article_chapter where chapterid in ( select max(chapterid) from xx_article_chapter GROUP BY articleid)
3. 基于2个表的更新
update xx_article_article as tablea,
(select * from xx_article_chapter where chapterid in ( select max(chapterid) from xx_article_chapter GROUP BY articleid)) as tableb
set tablea.lastchapter = tableb.chaptername,tablea.lastchapterid = tableb.chapterid where tablea.articleid = tableb.articleid
原文章%77w%77%2Ef%6F%72%61%73%70%2E%63n
·上一篇:mysql 中文乱码 >> ·下一篇:windows11安装redis >>