0

如何在一个 MySQL 数据库查询中使用 1 个交叉连接和 2 个左连接(总和分组)?

以下工作,但计数结果是错误的(它返回COUNT- 相同的结果和错误的结果)。

SELECT 
    n_users.username, n_users.email,
    COUNT(n_messages.ads_id ) AS msg_cnt, 
    COUNT(`n_coversation`.user_id ) AS cnv_cnt,
    SUM(n_transaction.debit), SUM(n_transaction.credit) 

FROM 
    n_users JOIN (n_ads , n_messages) ON 
        (n_ads.user_id=n_users.id AND  n_messages.ads_id=n_ads.id )    
    LEFT JOIN n_coversation ON  (n_coversation.user_id=n_users.id) 
    LEFT JOIN n_transaction ON (n_transaction.user_id=n_users.id)

WHERE  
    n_users.id =5

GROUP BY 
    n_transaction.user_id
4

0 回答 0