SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with cte as( SELECT YEAR(p.payment_date) AS income_year, CONCAT(s.last_name, ' ', s.first_name) AS staff, SUM(p.amount) AS total_payments FROM payment p JOIN staff s USING(staff_id) GROUP BY income_year, staff WITH ROLLUP) SELECT t.income_year, WHERE CASE t.staff WHEN t.income_year='Total' THEN t.staff = '' ELSE 1 END AS staff, t.total_payments FROM( SELECT IFNULL(cte.income_year,'Total') AS income_year, IFNULL(cte.staff,'Year total') AS staff, cte.total_payments FROM cte) as t

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear