我有一个包含response_id、question_id和answer_id列的表。
我想找到所有的response_id匹配的多个条件。例如,下面是一些用法
在SQL中,我可以使用INTERSECT来完成这个任务,但是在MySQL中不能使用这个互斥库。有人能指导我如何解决这个问题吗?
示例在SQL中,这在MySQL中是需要的。
select distinct(response_id) from table where question_id = 873 AND answer_id = 5269
intersect
select distinct(response_id) from table where question_id = 874 AND answer_id = 5273
intersect
select distinct(response_id) from table where question_id = 877 AND answer_id = 5286发布于 2018-04-22 14:02:39
MySQL不支持INTERSECT,但是我们可以使用EXISTS子句来模拟它:
SELECT DISTINCT response_id
FROM table
WHERE
question_id = 873 AND
answer_id = 5269 AND
response_id IN (
SELECT DISTINCT response_id FROM yourTable
WHERE question_id = 874 AND answer_id = 5273) AND
response_id IN (
SELECT DISTINCT response_id FROM yourTable
WHERE question_id = 877 AND answer_id = 5286);发布于 2018-04-22 13:53:50
SELECT DISTINCT * FROM
(SELECT table.response_id FROM table, data WHERE table.question_id = 873 AND
table.answer_id = 5269) query1
INNER JOIN
(SELECT table.response_id FROM table, data WHERE table.question_id =874 AND
table.answer_id = 5273) query2https://stackoverflow.com/questions/49966606
复制相似问题