SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
select sa.store_id, case when sum(case when month(p.payment_date) between 1 and 3 then p.amount end) is null then 0 else sum(case when month(p.payment_date) between 1 and 3 then p.amount end) end as 'I', case when sum(case when month(p.payment_date) between 4 and 6 then p.amount end) is null then 0 else sum(case when month(p.payment_date) between 4 and 6 then p.amount end) end as 'II', case when sum(case when month(p.payment_date) between 7 and 9 then p.amount end) is null then 0 else sum(case when month(p.payment_date) between 7 and 9 then p.amount end) end as 'III', case when sum(case when month(p.payment_date) between 10 and 12 then p.amount end) is null then 0 else sum(case when month(p.payment_date) between 10 and 12 then p.amount end) end as 'IV' from payment p join staff sa using(staff_id) where (year(r.rental_date) = 2005) group by 1;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear