gpt4 book ai didi

mysql - 获取查询结果的子集

转载 作者:行者123 更新时间:2023-12-01 00:12:47 26 4
gpt4 key购买 nike

request 表有外键字段jobuser。我需要提取一个用户同时拥有 job = 35 和 job = 34 的行的子集。

这个查询是否正确地完成了工作?我相信是的。

SELECT * FROM `request` 
WHERE `job` = 35 AND `fulfilled` is NULL
AND
`user` IN
(SELECT `user` FROM `request` WHERE `job` = 34 AND `fulfilled` is NULL )

最佳答案

SELECT user
FROM request
WHERE job IN (34,35) AND `fulfilled` is NULL
GROUP BY user
HAVING COUNT(DISTINCT job) = 2

关于mysql - 获取查询结果的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163357/

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