我有一個連接到點的數據的MySQL表。像這樣:Mysql:選擇指定點之間的所有數據
tbl_user
tbl_earned_points
tbl_used_points
我有一個MySQL查詢選擇可用點的數據。這是查詢:
SELECT
user.user_email_id AS userEmailId,
IFNULL(SUM(earn_points.earned_points),0) AS lifeTimePoints,
IFNULL((SUM(earn_points.earned_points) - (SELECT IFNULL(SUM(used_points.points_used),0) FROM tbl_used_points AS used_points WHERE used_points.user_id=earn_points.user_id)),0) AS availablePoints
FROM tbl_earned_points AS earn_points
RIGHT JOIN tbl_user AS user ON earn_points.user_id=user.user_id WHERE user.user_email_id <> '' AND user.user_email_id <> '0'
GROUP BY user.user_email_id
ORDER BY availablePoints ASC
從上面的查詢我收到的所有電子郵件&結果像
userEmailId lifeTimePoints availablePoints
[email protected] 1745 1500
[email protected] 100 75
[email protected] 85 85
[email protected] 94 90
[email protected] 547 450
我的問題是,我只需要得到各行availablePoints 80到99。
所以會導致我的查詢像
userEmailId lifeTimePoints availablePoints
[email protected] 85 85
[email protected] 94 90
#1054 - 在 'where子句' – user2046091 2014-09-20 06:50:48