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
FrankAdler
V2EX  ›  MySQL

对于 in 查询,如何限制每个组合数据的条数呢

  •  
  •   FrankAdler · 2022-12-09 20:32:43 +08:00 · 1196 次点击
    这是一个创建于 474 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如 uid in (1001,1002) and type in (1,2)

    uid 可能有很多,比如 60 个,type 每种只取最后一个,最终数据最多 60*2=120 条

    相当于 uid = 1001 and type in(1,2) order by id limit 1 这样查询 60 次,现在想一条 sql 解决

    4 条回复    2022-12-10 00:47:02 +08:00
    chinni
        1
    chinni  
       2022-12-09 20:39:31 +08:00
    row_number ,partition by , order by
    FrankAdler
        2
    FrankAdler  
    OP
       2022-12-09 23:05:05 +08:00
    @chinni 感谢,我研究下看看
    liaohongxing
        3
    liaohongxing  
       2022-12-10 00:03:33 +08:00
    搜一下窗口函数
    FrankAdler
        4
    FrankAdler  
    OP
       2022-12-10 00:47:02 +08:00
    @liaohongxing 好的,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5483 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 08:16 · PVG 16:16 · LAX 01:16 · JFK 04:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.