TRICKY SQL Interview Question | SQL Intermediate Question 20

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

Пікірлер: 7

  • @snehithasingam9918
    @snehithasingam99183 ай бұрын

    explanation 👌

  • @MusicalShorts-hn1px
    @MusicalShorts-hn1px2 ай бұрын

    Thanks for posting the problem along with data set

  • @saib7231
    @saib7231Ай бұрын

    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

  • @harshkumargupta1348
    @harshkumargupta13482 ай бұрын

    Cant we do this Select taxmonth, Max(clothing+electronics+sports) From eshop Group by 1

  • @saib7231

    @saib7231

    Ай бұрын

    no this is syntax wise all instead you can use this 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