Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个 SQL 表:
name | id_photo ================ word1 | 38 word2 | 38 word7 | 39 word1 | 31 word2 | 31
我想研究所有的 id_photo,例如 name = word1 AND name = word2 例如这种情况我想作为回报 38,31
有人可以提出解决方案吗?
SELECT ID_PHOTO FROM tableNAME WHERE name IN ('word1','word2') GROUP BY ID_PHOTO HAVING COUNT(*) = 2
如果没有在每个名称上指定唯一键,请在内部id_photo使用distinctCOUNT
id_photo
distinct
COUNT
SELECT ID_PHOTO FROM tableNAME WHERE name IN ('word1','word2') GROUP BY ID_PHOTO HAVING COUNT(DISTINCT name) = 2