› 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 · Dec 9, 2022 · 2226 views
    This topic created in 1387 days ago, the information mentioned may be changed or developed.

    比如 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 replies  •  2022-12-10 00:47:02 +08:00
    chinni
        1
    chinni  
       Dec 9, 2022
    row_number ,partition by , order by
    FrankAdler
        2
    FrankAdler  
    OP
       Dec 9, 2022
    @chinni 感谢,我研究下看看
    liaohongxing
        3
    liaohongxing  
       Dec 10, 2022
    搜一下窗口函数
    FrankAdler
        4
    FrankAdler  
    OP
       Dec 10, 2022
    @liaohongxing 好的,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2745 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:29 · PVG 22:29 · LAX 07:29 · JFK 10:29
    ♥ Do have faith in what you're doing.