Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT user_id,
- SUM(COALESCE(point_points, 0)) AS total_points,
- SUM(
- CASE
- WHEN point_date > '$this_month'
- THEN point_points
- ELSE 0
- END) AS month_points,
- COUNT(DISTINCT c_id) AS num_comments,
- COUNT(DISTINCT rant_id) AS live_submissions
- FROM users
- LEFT JOIN points
- ON users.user_id = points.point_userid
- LEFT JOIN comments
- ON
- (
- c_userid = user_id
- )
- LEFT JOIN rants
- ON
- (
- rant_poster = user_id
- AND rant_status = 1
- )
- WHERE user_id = $id
- GROUP BY user_id
- SELECT u.user_id, SUM(COALESCE(p.point_points, 0)) AS total_points,
- SUM( CASE WHEN p.point_date > '$this_month' THEN p.point_points ELSE 0 END ) AS month_points
- FROM users u LEFT JOIN points p
- ON u.user_id = p.point_userid
- WHERE u.user_id = $id
- GROUP BY u.user_id;
- SELECT user_id, COUNT(c.c_id) as num_comments,
- FROM users u LEFT JOIN comments c
- ON (c.c_userid = u.user_id)
- WHERE u.user_id = $id
- GROUP BY u.user_id;
- SELECT u.user_id, COUNT(r.rant_id) as live_submissions
- FROM users u LEFT JOIN rants r
- ON (r.rant_poster = u.user_id AND r.rant_status = 1)
- WHERE u.user_id = $id
- GROUP BY u.user_id;
- SELECT UserId, C.num_comments, P.total_points
- FROM users
- LEFT JOIN
- (SELECT c_userId, COUNT(DISTINCT c_id) as num_comments
- FROM Comments
- GROUP BY c_userId)
- AS C
- ON UserId = c_userid
- LEFT JOIN
- (SELECT point_userId, sum(COALESCE(point_points, 0)) as total_points
- FROM Points
- GROUP BY point_userId)
- AS P
- ON UserId = point_userid
Add Comment
Please, Sign In to add comment