I have this query which helps me to get the points for a current user, now, i have a problem on setting a condition...
$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';
My problem is the AND u.user_id="'.$_SESSION['user_name'].'"
I need to find the points for this specific user.. Am i doing something wrong with it? I mean, i know i am, but what? Thanks
write your query like this
$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';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.