0

该表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 )
4

1 回答 1

7
SELECT user
FROM   request
WHERE  job IN (34,35) AND `fulfilled` is NULL 
GROUP BY user
HAVING COUNT(DISTINCT job) = 2
于 2012-10-31T17:21:17.130 回答