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

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

  •  
  •   ruandao · 2020-01-16 21:44:05 +08:00 · 2902 次点击
    这是一个创建于 1560 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 
    

    谢谢

    第 1 条附言  ·  2020-01-17 14:50:45 +08:00

    找到解法了

    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 条回复    2020-01-17 12:47:21 +08:00
    tairan2006
        1
    tairan2006  
       2020-01-17 08:47:20 +08:00 via Android
    先 join 然后用 where 不就可以了?
    no1xsyzy
        2
    no1xsyzy  
       2020-01-17 12:47:21 +08:00
    你可以把老二插电风扇里
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5832 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 277ms · UTC 06:14 · PVG 14:14 · LAX 23:14 · JFK 02:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.