select month, sum(case when category = 'clothing' then amount end )as clothing, sum(case when category = 'electronics' then amount end )as electronics from sales_data group by month
SELECT * FROM SALES_DATA SELECT MONTH,MAX(CASE WHEN CATEGORY='ELECTRONICS'THEN AMOUNT END) AS ELECTRONICS ,MAX(CASE WHEN CATEGORY='CLOTHING' THEN AMOUNT END) AS CLOTHING FROM SALES_DATA GROUP BY MONTH ORDER BY MONTH
select month, sum(if(category="electronics",amount,null)) as electronics, sum(if(category="clothing",amount,null)) as clothing from sales_data group by 1 order by 1;
select month,
sum(case when category = 'clothing' then amount end )as clothing,
sum(case when category = 'electronics' then amount end )as electronics
from sales_data
group by month
@devarajululanka6427 Great! Keep practicing :) Let us know if you need us to solve any particular question.
fantastic
Thank you! Cheers!
SELECT * FROM SALES_DATA
SELECT MONTH,MAX(CASE WHEN CATEGORY='ELECTRONICS'THEN AMOUNT END) AS ELECTRONICS
,MAX(CASE WHEN CATEGORY='CLOTHING' THEN AMOUNT END) AS CLOTHING
FROM SALES_DATA
GROUP BY MONTH ORDER BY MONTH
@chandramohan-bo5se Great! Keep practicing :) Let us know if you need us to solve any particular question.
Without using crosstab, can do with group by, will the company accept it
Yes, how you interpret the problem and solve, it's completely upto you. Everyone has a different way of perceiving the problem and solving it.
select month,
sum(if(category="electronics",amount,null)) as electronics,
sum(if(category="clothing",amount,null)) as clothing
from sales_data
group by 1
order by 1;
@ishanshubham8355 Great! Keep practicing :) Let us know if you need us to solve any particular question.