我想相交2個querys在MySQL以這種方式:路口與MySQL與查詢
SELECT user_id FROM post GROUP BY thread_id HAVING COUNT(thread_id) = 1
INTERSECT
SELECT user_id FROM post GROUP BY user_id HAVING COUNT(user_id) = 1;
我已經看了各種方法來做到這一點在MySQL,但不幸的是使用IN和INNER JOIN還沒有爲我工作。
測試數據我工作是:
insert into post (post_number, timestamp, user_id, thread_id) values(0,0,1,1000);
insert into post (post_number, timestamp, user_id, thread_id) values(0,0,2,2000);
insert into post (post_number, timestamp, user_id, thread_id) values(0,0,3,2000);
insert into post (post_number, timestamp, user_id, thread_id) values(0,0,4,3000);
insert into post (post_number, timestamp, user_id, thread_id) values(0,0,5,4000);
insert into post (post_number, timestamp, user_id, thread_id) values(0,0,1,4000);
運行我的兩個查詢的交集應該導致
4
任何幫助表示讚賞,感謝。
當你運行你的查詢您能得到什麼? –
你的交集的第一部分是無效的sql:你不能選擇你沒有分組的東西。這在MySql中有效嗎?你在第一個陳述中表達了什麼概念?它是否選擇僅在一個線程中發佈的用戶?用戶是線程中唯一的海報? – jkebinger