MYSQL SUM双重结果

时间:2012-05-22 07:15:25

标签: mysql sql sum

我有以下SQL但SUM返回意外值...我无法弄清楚如何纠正它。

SQL:

SELECT 
    SUM(logs.amount*ei_relationships.itemprice) as spend, 
    SUM(log_users.amount) as recharged, 
    logs.cardid, 
    count(log_users.amount) as recharges 
FROM log_users
INNER JOIN logs ON logs.cardid = log_users.cardid
INNER JOIN ei_relationships ON ei_relationships.id = logs.ei_relationship_id
WHERE ei_relationships.event_id = 2 
GROUP BY logs.cardid 
ORDER BY recharged DESC

ei_relationship有很多日志,还有很多log_users。我尝试了不同的东西,但无法弄明白。

0 个答案:

没有答案