1

我有这个查询可以帮助我获得当前用户的积分,现在,我在设置条件时遇到了问题......

$query4 =  'SELECT u.*, SUM(c.ts) AS total_sum1, SUM(r.bv) AS total_sum 
FROM users u 
LEFT JOIN 
 (SELECT user_id ,SUM(points) AS ts FROM coupon GROUP BY user_id) c 
 ON u.user_id=c.user_id AND u.user_id="'.$_SESSION['user_name'].'"
LEFT JOIN 
 (SELECT user_id ,SUM(basket_value) AS bv FROM retailer GROUP BY user_id) r 
ON u.user_id=r.user_id 
GROUP BY u.user_id';

我的问题是AND u.user_id="'.$_SESSION['user_name'].'"

我需要找到这个特定用户的积分。我做错了什么吗?我的意思是,我知道我是,但是什么?谢谢

4

1 回答 1

1

像这样写你的查询

$query4 =  'SELECT u.*, SUM(c.ts) AS total_sum1, SUM(r.bv) AS total_sum 
FROM users u 
LEFT JOIN 
 (SELECT user_id ,SUM(points) AS ts FROM coupon GROUP BY user_id) c 
 ON u.user_id=c.user_id 
LEFT JOIN 
 (SELECT user_id ,SUM(basket_value) AS bv FROM retailer GROUP BY user_id) r 
ON u.user_id=r.user_id 
where u.user_id="'.$_SESSION['user_name'].'"
GROUP BY u.user_id';
于 2012-11-16T09:51:35.670 回答