SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
WITH tmp AS ( SELECT YEAR(payment_date) AS income_year, CONCAT(last_name, ' ',first_name) AS staff, SUM(amount) AS total_paiments, IF(GROUPING(YEAR(payment_date)) = 1, 'Total', 200) as gr FROM payment p JOIN staff s ON p.staff_id = s.staff_id GROUP BY income_year, staff WITH ROLLUP ) SELECT COALESCE(income_year, 'Total') AS income_year, COALESCE(staff, 'Year total', '') AS staff, total_paiments, gr FROM tmp

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear