TRICKY SQL Interview Question | SQL Intermediate Question 20

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
Question - Write an SQL query ๐ญ๐จ ๐Ÿ๐ข๐ง๐ ๐ญ๐ก๐ž ๐ญ๐ฑ๐ง๐ฆ๐จ๐ง๐ญ๐ก ๐ฐ๐ก๐ข๐œ๐ก ๐ก๐š๐ฌ ๐ญ๐ก๐ž ๐ฆ๐š๐ฑ๐ข๐ฆ๐ฎ๐ฆ ๐ญ๐ฑ๐ง๐š๐ฆ๐จ๐ฎ๐ง๐ญ
The approach is to arrange the data vertically so that applying aggerate functions becomes easy.
Comment below yours approach too.

create table eshop(txnmonth varchar(50),clothing int,electronics int,sports int);
insert into eshop values('Jan',2000,1500,3000);
insert into eshop values('Feb',1000,2500,4000);
insert into eshop values('Mar',2000,1400,1000);
insert into eshop values('Apr',3000,1500,1000);
select * from eshop;

#amazon #facebook #meta #ai #dataanalytics #placement #college #sql #tcs #cts #infosys
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

Thanks for posting the problem along with data set

MusicalShorts-hnpx
ะะฒั‚ะพั€

select top 1 txnmonth, (clothing+electronics+sports) AS amount
from eshop
ORDER BY amount DESC;

Rmmstin
ะะฒั‚ะพั€

Cant we do this
Select taxmonth,
From eshop
Group by 1

harshkumargupta
ะะฒั‚ะพั€

Select taxmonth, sum(cast(clothing as int)+cast(electronics as int)+cast(sports as int)) as total_sales
From eshop
Group by taxmonth
order by total_sales desc
limit 1

this als works

saib