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(r.rental_date) between 1 and 3 then p.amount end) is null then 0 else sum(case when month(r.rental_date) between 1 and 3 then p.amount end) end as 'I', case when sum(case when month(r.rental_date) between 4 and 6 then p.amount end) is null then 0 else sum(case when month(r.rental_date) between 4 and 6 then p.amount end) end as 'II', case when sum(case when month(r.rental_date) between 7 and 9 then p.amount end) is null then 0 else sum(case when month(r.rental_date) between 7 and 9 then p.amount end) end as 'III', case when sum(case when month(r.rental_date) between 10 and 12 then p.amount end) is null then 0 else sum(case when month(r.rental_date) between 10 and 12 then p.amount end) end as 'IV' from store so join staff sa using(store_id) join rental r using (staff_id) join payment p using(rental_id) group by 1; ; show status like 'Last_query_cost';

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear