SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
select ifnull(income_year,'Total') as income_year, case when staff is null and income_year is not null then 'Year total' else ifnull(staff,'') end as staff, sum(amount) as 'total_paiments' from ( select year(p.payment_date) as 'income_year', concat(s.last_name,' ', s.first_name) as 'staff', sum(amount) as 'amount' from payment p inner join staff s on s.staff_id = p.staff_id group by year(p.payment_date), concat(s.last_name,' ', s.first_name) order by year(p.payment_date) ) t group by income_year, staff with rollup ; show status like 'Last_query_cost';

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear