Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
with t1 as(SELECT YEAR(payment_date) AS income_year, CONCAT(last_name,' ', first_name) as staff, SUM(amount) AS total_payments FROM payment join staff using(staff_id) GROUP BY YEAR(payment_date), staff WITH ROLLUP ORDER BY income_year IS NULL, -- Сначала строки с годом (NULL в конце) income_year, staff IS NULL, -- Сначала строки с staff_id (NULL в конце) staff) select IFNULL(income_year, 'Total') AS income_year, IFNULL(staff, CASE WHEN income_year IS NOT NULL THEN 'Year total' ELSE ' ' END ) AS staff, total_payments from t1

Stuck with a problem? Got Error? Ask AI support!

Copy Clear