Advertisement
Gistrec

SQL Join users with transactions and rebills

Feb 6th, 2022
1,351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. SELECT u.first_name, u.last_name, u.user_name, u.phone, u.name, SUM(IF(t.status = "CONFIRMED", t.amount, 0) )AS sum,
  2.        GROUP_CONCAT(CONCAT(t.payment_id, "-", t.amount, "-", t.status, "-", t.error_code, COALESCE(t.pan, 'null'), "-", COALESCE(t.exp_date, "null"), "-", t.time)) AS transactions,
  3.        GROUP_CONCAT(CONCAT(r.rebill_id,  "-", r.amount, "-", r.active, "-", r.last_success_payment, "-", COALESCE(r.last_reject_payment, "null"), "-", r.error_count)) AS rebills
  4. FROM users AS u
  5. LEFT JOIN transactions t ON u.user_id = t.user_id
  6. LEFT JOIN rebills      r ON u.user_id = r.user_id
  7. GROUP BY first_name, last_name, user_name, phone, name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement