I have following MySQL Tables:
TABLE: reg_users
-----------------
id | username
-----------------
1 a
2 b
3 c
TABLE: bill
-----------------------
id | m12 | p12 |
-----------------------
1 13.69 1
2 0.00 1
3 269.89 1
SELECT b.p12 AS payed,
d.id,
b.m12 AS prev_month,
b.m12 AS curr_month,
username,
SUM(b.m12) AS total_prev_month
FROM `reg_users` d
LEFT JOIN `bill` b ON d.id = b.id
ORDER BY d.`id` DESC;
I only get one row result and need to get all results (3 rows result with total_prev_month SUMMED together for each row so this row need to have values for each row 283.58.
Using GROUP BY i get correct total_prev_month value but i get only one row results...and i need in this example 3 rows results like:
------------------------------------------------
payed | id | username | total_prev_month
------------------------------------------------
1 1 a 283.58
1 2 b 283.58
1 3 c 283.58
SUM(b.m12) OVER () AS total_prev_monthSUM(b.m12) OVER () AS total_prev_monthmight be used for DB version 8.0, what's your DB version?