gpt4 book ai didi

php - SQL结果来自不同领域的研究

转载 作者:行者123 更新时间:2023-11-29 08:42:28 26 4
gpt4 key购买 nike

我有这个 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 的名称上指定唯一键,请在 COUNT 内使用 distinct

SELECT ID_PHOTO
FROM tableNAME
WHERE name IN ('word1','word2')
GROUP BY ID_PHOTO
HAVING COUNT(DISTINCT name) = 2

关于php - SQL结果来自不同领域的研究,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13418753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com