我有以下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
。我尝试了不同的东西,但无法弄明白。