我有這樣的查詢,如何將這兩個結果合併爲一個在mysql中?
SELECT b.user_id,b.first_name, b.last_name, b.email_id,
COUNT(DISTINCT a.file_id) AS sharedFiles
FROM email_history a, users b
WHERE a.email_receiver_id = b.user_id
AND a.email_sender_id= 20
GROUP BY b.user_id,b.first_name, b.last_name, b.email_id
UNION
SELECT b.user_id,b.first_name, b.last_name, b.email_id,
COUNT(DISTINCT a.file_id) AS sharedFiles
FROM email_history a, users b
WHERE a.email_sender_id = b.user_id
AND a.email_receiver_id= 20
GROUP BY b.user_id,b.first_name, b.last_name, b.email_id;
它的輸出中是 -
user_id first_name last_name email_id sharedFiles
17 Mohan Sharma [email protected] 2
17 Mohan Sharma [email protected] 1
它顯示兩個不同的記錄。但我想這樣的輸出 -
user_id first_name last_name email_id sharedFiles
17 Mohan Sharma [email protected] 3
我是新的mysql,所以請幫助我如何得到這個輸出。
謝謝。
做了一些編輯,它的工作,謝謝你 – Aamir