TRICKY SQL Interview Question | SQL Intermediate Question 20
Вставка
- Опубліковано 29 кві 2024
- 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
explanation 👌
Thanks for posting the problem along with data set
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
Cant we do this
Select taxmonth, Max(clothing+electronics+sports)
From eshop
Group by 1
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