0
我正在使用此查詢從3個表中獲取數據。使用加入運行查詢時結果增加一倍
SELECT sum(tu.filesize) AS totalSize, tu.sender, tu.receiver, tu.valid_time, group_concat(tu.filename) AS files, tu.file_path, us.uid temp_id, tu.unique_key, tu.uid user_id, tu.file_encryption, t_l.encryption_password
FROM tbl_uploads tu
LEFT JOIN tbl_users us ON us.id = tu.uid
LEFT JOIN tbl_logs t_l ON t_l.u_key = tu.unique_key
WHERE date(tu.valid_time) = '2014-01-09'
AND tu.sender <> ''
GROUP BY tu.unique_key
,但沒有得到預期的結果,因爲tbl_uploads
和tbl_logs
幾乎與名稱filesize, filename
同場,所以當我運行此查詢我得到了雙重文件大小462804
和文件;文件大小應爲231402
我不認爲這是因爲在tbl_logs類似的領域。您可能會多次獲取tbl_uploads中的行,因爲tlb_logs中有多行與tbl_uploads中的一行有關。 – Rembunator
@Rembunator yes在'tbl_logs'中也有多行,與'tbl_uploads'相同,但是在'tbl_uploads'中,我用group by做了單行的結果,但是由tbl_logs的組不行,以及我也嘗試過。像'GROUP BY tu.unique_key,t_l.u_key' –