SELECT a.id, a.username, a.email, a.created, b.user_id,
SUM((b.price >500) +100) + SUM(b.price) AS gr, SUM(b.price) AS pris,
b.created, c.user_id, c.referrer_id, c.created, d.id, d.beginner, d.winner_id
FROM users a, accounts b, referrals c, product d
WHERE a.created
BETWEEN '2013-05-01'
AND '2013-05-31'
AND a.id = b.user_id
AND a.id = c.user_id
AND d.beginner != '1'
AND d.winner_id = a.id
GROUP BY c.referrer_id
ORDER BY `pris` ASC
LIMIT 0 , 3
我已經制定了這個查詢。的問題,我想在這解決的是與查詢內計算
SUM((b.price >500) +100) + SUM(b.price) AS gr
我希望它可以像計算如果ID的總價格是一個超過500個月然後添加100.我完全不知道怎麼樣我應該在此查詢中計算一個人的總價格,並且如果一個月內的計數超過500,那麼應加上100?