AMAZON DATA ENGINEER Interview Question | SQL Intermediate Question 10
Вставка
- Опубліковано 14 жов 2024
- Question - Find total transactions through Cash and Online mode.
The question has been solved using aggregate functions and case condition.
#amazon #netflix #facebook #google #microsoft #flipkart #sqldeveloper #dataanalytics #dataengineering #sqlserver #placement #placements #interviewquestions #ml #ai
Thanks for your content.
Can you please add below in description which would help
create table merchant(merchant_id varchar(20) , amount int, payment_mode varchar(20));
insert into merchant values ('m1',200,'cash'),('m2',520,'online'),('m1',700,'online'),('m3',1400,'online'),('m2',50,'cash'),('m1',300,'cash');
select * from merchant;
Can we do partition on Payment mode and seperate the online and cash mode with row number as 1 for cash and row number as 2 for online....
And then case statement in which sum of R1 gives the value and puts 0 for online.
Similarly another case statement in which sum of R2 gives the value and puts 0 for cash.
Please let me know if this approach is correct or not.
same solution as you in MSSQL DB
Select merchant_id
,sum(case when payment_mode = 'cash' then amount else 0 end ) as Cash
,sum(case when payment_mode = 'online' then amount else 0 end ) as Online
from payments
group by merchant_id
order by sum(case when payment_mode = 'cash' then amount else 0 end) desc
Could u please provide data set so that we can practice along with u
Will definitely provide in the upcoming videos.
data?
Will definitely provide in the upcoming videos.
Group by merchant_id , cash_mode