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

如何用 sql 找出具有相同外键的 关系

  •  
  •   ruandao · Jan 16, 2020 · 3384 views
    This topic created in 2337 days ago, the information mentioned may be changed or developed.

    mysql 中

    表(hell)的结构:
    fk_field_1, fk_field_2
    

    然后想要找出

    fk_field_2 = (fk_field_2_1, fk_field_2_2, fk_field_2_3) 的  fk_field_1 要怎么写 sql 
    

    谢谢

    Supplement 1  ·  Jan 17, 2020

    找到解法了

    select * 
    from Parents p
    where 3 = (
        select Count(DISTINCT c.xId)
        from Child c
        where p.id = c.pid
            and c.xid in (4,5,6)
    )
    
    2 replies    2020-01-17 12:47:21 +08:00
    tairan2006
        1
    tairan2006  
       Jan 17, 2020 via Android
    先 join 然后用 where 不就可以了?
    no1xsyzy
        2
    no1xsyzy  
       Jan 17, 2020
    你可以把老二插电风扇里
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   882 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:50 · PVG 04:50 · LAX 13:50 · JFK 16:50
    ♥ Do have faith in what you're doing.