这是我的第一个查询
SELECT DISTINCT(u.nickname) FROM user u
where u.id IN(SELECT `submission_user`.`user_id` from `submission_user`) AND
u.member_since >= '2015-07-01'
这是我的第二个查询
SELECT DISTINCT(u.nickname) FROM user u LEFT JOIN submission_user su ON su.user_id = u.id
LEFT JOIN submission s ON s.id = su.submission_id
WHERE s.date_time BETWEEN '2017-10-31' and '2018-07-31'
这是我的第三个查询
SELECT DISTINCT(u.nickname) FROM user u LEFT JOIN submission_user su ON su.user_id = u.id
LEFT JOIN track_user tu ON tu.user_id = u.id
LEFT JOIN track ON track.id = tu.track_id
where track.uploaded_timestamp BETWEEN '2017-10-31' and '2018-07-31'
然后,我将第二和第三查询结果合并
$ids_reactivated = array_unique(array_merge($track_user, $submit_user));
所以我的问题是,如果我想减去一个查询结果以将结果均值与(查询2和3)合并,即我的情况:$ ids_reactivated
任何人都有一个想法如何做... 我已经尝试了很多方法,并度过了一天...
希望人们能帮助我
答案 0 :(得分:3)
感谢您的提示,但我得到了这样的答案...
SELECT DISTINCT(u.nickname) FROM user u
where u.id IN(SELECT `submission_user`.`user_id` from `submission_user`) AND
u.member_since >= '2015-07-01'
**and u.nickname not in ($query2)**
UNION
SELECT DISTINCT(u.nickname) FROM user u
where u.id IN(SELECT `submission_user`.`user_id` from `submission_user`) AND
u.member_since >= '2015-07-01'
**and u.nickname not in ($query3)**
答案 1 :(得分:1)
很简单,您可以利用并集进行合并,而不能进行减法 以下是示例
SELECT DISTINCT(u.nickname) FROM user u LEFT JOIN submission_user su ON su.user_id = u.id LEFT JOIN submission s ON s.id = su.submission_id
WHERE s.date_time BETWEEN '2017-10-31' and '2018-07-31'
**and u.nickname not in ($query1)**
UNION
SELECT DISTINCT(u.nickname) FROM user u LEFT JOIN submission_user su ON su.user_id = u.id LEFT JOIN track_user tu ON tu.user_id = u.id LEFT JOIN track ON track.id = tu.track_id
where track.uploaded_timestamp BETWEEN '2017-10-31' and '2018-07-31'
**and u.nickname not in ($query1)**
用查询更改$ query1,它应该给出结果