gpt4 book ai didi

php - 选择与另一列相关的唯一值

转载 作者:行者123 更新时间:2023-11-29 04:38:34 26 4
gpt4 key购买 nike

我有一个这样的表:

╔════╦════════════╦══════════╗
║ id ║ project_id ║ document ║
╠════╬════════════╬══════════╣
║ 1 ║ 1 ║ 3 ║
║ 2 ║ 1 ║ 5 ║
║ 3 ║ 2 ║ 3 ║
║ 4 ║ 2 ║ 4 ║
║ 5 ║ 3 ║ 5 ║
║ 6 ║ 4 ║ 2 ║
╚════╩════════════╩══════════╝

我想要所有 project_id 没有 document = 5

换句话说,我想要这个结果:

╔════════════╗
║ project_id ║
╠════════════╣
║ 2 ║
║ 4 ║
╚════════════╝

最佳答案

试试这个:

SELECT project_id
FROM mytable
GROUP BY project_id
HAVING COUNT(CASE WHEN document = 5 THEN 1 END) = 0

Demo here

关于php - 选择与另一列相关的唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35194908/

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