V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
listen2wind
V2EX  ›  MySQL

请教一个问题: mysql 中使用 group by 如何获取最新一条数据?

  •  
  •   listen2wind · 2022-09-06 11:09:59 +08:00 · 1561 次点击
    这是一个创建于 569 天前的主题,其中的信息可能已经有所发展或是发生改变。

    mysql 版本:8.0.28

    4 条回复    2022-09-06 13:39:23 +08:00
    hidemyself
        1
    hidemyself  
       2022-09-06 11:14:20 +08:00   ❤️ 1
    你需要 rank() over
    spicecch
        2
    spicecch  
       2022-09-06 11:31:22 +08:00   ❤️ 1
    PARTITION BY
    wxf666
        3
    wxf666  
       2022-09-06 11:38:22 +08:00   ❤️ 2
    https://dev.mysql.com/doc/refman/8.0/en/example-maximum-column-group-row.html

    文中说了 子查询、相关子查询、自连接、窗口函数 4 种方法
    hay313955795
        4
    hay313955795  
       2022-09-06 13:39:23 +08:00   ❤️ 1
    select * from table where id in (select Max(id) from table group by xxx ) 这样
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   962 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:41 · PVG 05:41 · LAX 14:41 · JFK 17:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.