Тёмный

Microsoft SQL Interview Question for Data Engineer Position | Data Analytics 

Ankit Bansal
Подписаться 119 тыс.
Просмотров 35 тыс.
50% 1

In this video we will discuss a problem asked in a Microsoft interview for Data Engineer Position. In this problem we have to write a SQL to build a team with a combination of seniors and juniors within a given salary budget.
We will discuss the step by step approach to solve the problem and see how powerful are SQL common table Expressions (CTE).
Zero to hero(Advance) SQL Aggregation:
• All About SQL Aggregat...
Most Asked Join Based Interview Question:
• Most Asked SQL JOIN ba...
Solving 4 Trick SQL problems:
• Solving 4 Tricky SQL P...
Data Analyst Spotify Case Study:
• Data Analyst Spotify C...
Top 10 SQL interview Questions:
• Top 10 SQL interview Q...
Interview Question based on FULL OUTER JOIN:
• SQL Interview Question...
Playlist to master SQL :
• Complex SQL Questions ...
Rank, Dense_Rank and Row_Number:
• RANK, DENSE_RANK, ROW_...
script:
create table candidates (
emp_id int,
experience varchar(20),
salary int
);
delete from candidates;
insert into candidates values
(1,'Junior',10000),(2,'Junior',15000),(3,'Junior',40000),(4,'Senior',16000),(5,'Senior',20000),(6,'Senior',50000);
#sql #dataengineer #microsoft #interview

Наука

Опубликовано:

 

17 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 132   
@pinaakgoel2937
@pinaakgoel2937 2 года назад
Hi Ankit, I did via following approach :- with senior_cte as (select *,sum(salary) over(order by salary) as rn_sum_sen from candidates where experience = 'Senior'), junior_cte as (select *,sum(salary) over(order by salary) as rn_sum_jun from candidates where experience = 'Junior') select emp_id,experience from senior_cte where rn_sum_sen
@ankitbansal6
@ankitbansal6 2 года назад
This is good. It can be simplified a bit.. check out my solution
@RK-pi1kr
@RK-pi1kr 2 года назад
Another great video and good answers. While complex queries work, for easier maintenance, it is always advisable to write a step by step query so that third person can easily read it and modify when new requirements come in else new person will end up more time analyzing the query.
@rashmidutta7151
@rashmidutta7151 2 года назад
just wow!! I thought that this can be done by recursion!! But you did it so gracefully
@shekharagarwal1004
@shekharagarwal1004 2 года назад
Thanks a lot ank(IT) , you always have different approach which becomes adding to our knowledge bank. I have used your earlier dynamic union approach of Sachin milestone problem . with cte as ( SELECT * ,SUM(salary) over ( partition by experience order by salary) as runing_sum FROM candidates ) , team_budget as ( SELECT 70000 as budget ) , cte2 as ( SELECT * , SUM(c.salary) over ( order by c.experience Desc , c.salary) as runing_sum1 FROM cte c JOIN team_budget tb ON c.runing_sum
@sourabhgupta1428
@sourabhgupta1428 3 месяца назад
Amazing question Ankit. Here is my solution to that: with cte as( select *, sum(salary) over(partition by experience order by experience desc,salary asc) as running_sal from candidates ), senior_hired as (select * from cte where experience='senior' and running_sal
@Useracwqbrazy
@Useracwqbrazy Год назад
The solution i did in first attempt...am regularly watching ur playlist from 15 days....thank u Ankit... with cte as (select *,sum(salary) over(partition by experience order by experience,salary) as sum_sal from candidates ) , cte1 as(select * from cte where sum_sal
@ankitbansal6
@ankitbansal6 Год назад
Awesome
@thebongwanderluster
@thebongwanderluster 2 года назад
Your approach is simpler and cleaner.My own complicated approach: with cte as( select emp_id,experience,salary,SUM(salary) over (partition by experience order by experience desc,salary asc rows between unbounded preceding and current row)-salary AS CUM_SUM FROM CANDIDATES order by experience desc), senior_cte as( SELECT emp_id,experience,salary,CUM_SUM,(70000-CUM_SUM) as remaining,case when (70000-CUM_SUM)>=salary then 'select' else 'reject' end as status FROM CTE where experience like 'Senior'), junior_cte as( SELECT emp_id,experience,salary,CUM_SUM,case when experience='Junior' then (select min(remaining) from senior_cte) END -CUM_SUM as remaining,case when (select min(remaining) from senior_cte)-CUM_SUM >=salary then 'select' else 'reject' end as status FROM cte where experience like 'Junior' ) select emp_id,experience,salary from senior_cte where status='select' UNION select emp_id,experience,salary from junior_cte where status='select' order by emp_id ;
@ankitbansal6
@ankitbansal6 2 года назад
Great effort 😊
@NamanSeth1
@NamanSeth1 5 месяцев назад
Wonderful question Ankit. Here is my solution to that: with senior_hire as( select *, sum(salary) over (order by salary asc) run_sum from candidates where experience = 'Senior' qualify sum(salary) over (order by salary asc)
@anshumansrivastava2801
@anshumansrivastava2801 2 года назад
Hello Ankit, This is my approach. with cte1 as ( select *,(sum(salary) over(order by experience desc, salary asc)) as running_sal from candidates ) , cte2 as( select * from cte1 where running_sal
@Satish_____Sharma
@Satish_____Sharma 6 месяцев назад
Question is just amazing here is my try using MYSQL👍 with cte as (SELECT *,70000-sum(salary) over (partition by experience order by emp_id) as total FROM candidates where experience='Senior') ,cte1 as (select *,70000-sum(salary) over () as reamaining from cte where total>=0) ,cte2 as (SELECT *,(select max(reamaining) from cte1)-sum(salary) over (partition by experience order by emp_id) as total FROM candidates where experience='Junior') select emp_id, experience, salary from cte2 where total>=0 union all select emp_id, experience, salary from cte1
@aaravkumarsingh4018
@aaravkumarsingh4018 2 года назад
with cte as( select emp_id,experience,salary,sum(salary )over(partition by experience order by salary rows between unbounded preceding and current row) as running_salary from candidates ), cte1 as( select emp_id,experience,salary from cte where experience="Senior" and running_salary
@abb_raj1107
@abb_raj1107 2 года назад
Here is my different approach. Ankit bhai I agree this is perfect problem to highlight 'CTE' usage. Buz if we have more category of experience (eg. Senior,Mid,Junior), we need to create one more cte tb as category level inc. See my approach⬇ : with cte as (select * , sum(salary) over(order by experience desc,salary asc rows between unbounded preceding and current row) first_rs_salary from candidates ) ,cte2 as ( select *,sum(salary) over(order by experience desc,salary asc rows between unbounded preceding and current row) sec_rs_salary from cte where not (experience='Senior' and first_rs_salary > 70000)) select * from cte2 where sec_rs_salary
@karangupta_DE
@karangupta_DE 2 года назад
Thank you for another great video, i had solved the same question, but the output required in that question was just the count of seniors and juniors, instead of the actual rows. Your solution is more optimised than what I wrote. Thank you for the video once again.
@DE_Pranav
@DE_Pranav 2 месяца назад
with cte as ( select *, sum(salary) over(order by salary) as total from candidates ) select emp_id,experience,salary from cte where total
@shivarajhalageri2513
@shivarajhalageri2513 2 года назад
Make 2 ctes one senior employees and one junior employees, find the running sum in both the cases then take out senior employees whose running sum is less than 70000 and find the last running sum value of the senior employees that we have taken out subtract that from 70000 and and it will give some x then take out the running sum values of junior cte table who's values less than x, then combine these two with union all. Correct me if I am wrong @ankit 🙌
@ankitbansal6
@ankitbansal6 2 года назад
Perfect
@shivarajhalageri2513
@shivarajhalageri2513 2 года назад
@@ankitbansal6 will always be eagerly waiting for your every single video. I am Grateful for your each and every other video/content that you have put on RU-vid 🙌🙌🙌
@rabink.5115
@rabink.5115 2 года назад
Can you please post your queries here, it will be more helpful
@shivarajhalageri2513
@shivarajhalageri2513 2 года назад
@@rabink.5115 Sure will do that
@prinkeshshotri958
@prinkeshshotri958 2 года назад
I followed this method and it’s even simpler.
@ManishSharma-pn5dd
@ManishSharma-pn5dd 2 года назад
Hi Ankit can you have short series on data-modelling ? that will be very helpful.
@anirvansen2941
@anirvansen2941 Год назад
Yes , Agree , we need this , Ankit if you could help us wth data modelling playlist
@BismarckWangkhem
@BismarckWangkhem 2 года назад
Hi, here is my approach: with cte as (select *, sum(salary) over (partition by experience order by salary) running_sum from candidates), cte2 as ( select t.*, sum(t.salary) over (order by experience desc, t.salary asc) final_running_sum from (select * from cte where running_sum
@abhishekpurohit3442
@abhishekpurohit3442 2 года назад
Solved without any solutions: with cte1 as (select *, sum(salary) over(partition by experience order by salary rows between unbounded preceding and current row) as rn_sum from candidates), cte2 as ( select *,max(rn_sum) over(partition by experience) as max_rn_sum from cte1 where experience='Senior' and rn_sum
@ashwingupta4765
@ashwingupta4765 9 дней назад
with cte as ( select *, sum(salary) over(partition by experience order by salary) as cms from candidates) , cte1 as ( select * from cte where experience = 'senior' and cms
@parth_pm16
@parth_pm16 Год назад
Hi Ankit, I've completed your "Leetcode SQL Hard problem" playlist. Thank you for making content to help the Data enthusiast like me. I got to learn so many new ways to think to solve the questions which I don't think of previously. BTW I've purchased your SQL course also.
@ankitbansal6
@ankitbansal6 Год назад
Awesome. Keep learning 😊
@gauravmishra7471
@gauravmishra7471 2 года назад
Dear Ankit.. Many thanks for the clean code with perfect logic !! .. Keep up!! :)
@ankitbansal6
@ankitbansal6 2 года назад
Thank you 😊
@ananthram8062
@ananthram8062 Год назад
select * from candidates with cte as ( select*,sum(salary) over(order by salary ) as rnk from candidates ) select emp_id,experience,salary from cte where rnk
@FootballWithAnkit
@FootballWithAnkit 2 года назад
Great qn My sol is there is one more category named mid with t1 as( select *, sum(salary) over(partition by experience order by salary asc) as cum from candidates ), t2 as ( select *from t1 where experience='Senior' and cum
@anshulmehta8423
@anshulmehta8423 Год назад
with cte1 as (Select *,sum(salary) over(partition by experience order by salary) as d, 70000 as budget from Candidates) Select emp_id,experience,Salary from cte1 where d
@ashwinbhalerao8608
@ashwinbhalerao8608 2 года назад
Glad I found your channel man. Thank you so much for these questions!
@rawat7203
@rawat7203 4 месяца назад
My Way: with cte as( select *, sum(salary) over(partition by experience order by salary) as roll_sum from candidates order by experience desc), cte2 as( select emp_id, experience, salary from cte where roll_sum
@shubhambisht9090
@shubhambisht9090 Год назад
Amazing as u provide raw data for practice...
@BaBaYaGa-um4yg
@BaBaYaGa-um4yg 3 месяца назад
Please check : with cte as( select *,sum(salary) over(partition by experience order by salary asc) total_salary from candidates) ,senior_salary as ( select emp_id,experience,salary from cte where experience = 'senior' and total_salary
@kajoripaul7279
@kajoripaul7279 3 месяца назад
awesome..explained very well!!
@ankitbansal6
@ankitbansal6 3 месяца назад
Glad you liked it
@anirvansen2941
@anirvansen2941 6 месяцев назад
mysql solution with seniors as ( select *, sum(salary) over(order by salary asc rows between unbounded preceding and current row) as rolling_sum from candidates where experience = 'Senior' order by salary asc ), juniors as ( select *, sum(salary) over(order by salary asc rows between unbounded preceding and current row) as rolling_sum from candidates where experience = 'Junior' order by salary asc ), left_amount as ( select max(rolling_sum) as amount from seniors where rolling_sum < 50000 ), selected_junior as ( select * from juniors,left_amount where rolling_sum < amount ) select emp_id ,experience from seniors where rolling_sum < 50000 union select emp_id ,experience from selected_junior
@nomap5466
@nomap5466 8 месяцев назад
That’s a great question and explanation. Appreciate it
@ankitbansal6
@ankitbansal6 8 месяцев назад
My pleasure!
@shankrukulkarni3234
@shankrukulkarni3234 Год назад
SELECT * FROM interview_pre.candidates; with cte as( select *,sum(salary) over(partition by experience order by salary asc) as running_Sal from candidates), cte1 as (select * from cte where experience='Senior' and running_sal
@MOHITTIWARI-kb5ne
@MOHITTIWARI-kb5ne 2 года назад
Another good question with different approach
@sarthak810
@sarthak810 Год назад
with cte as( SELECT *,sum(salary) over(partition by experience order by salary) as r_summ, 70000 as max_sal FROM candidates), senior as( select *,(max_sal-r_summ) remaning_b from cte where experience = 'Senior' and r_summ < 70000), junior as( select * from cte where experience= 'Junior' and salary < (select max(r_summ) from senior) ), final as( select emp_id,experience,salary from senior union all select emp_id,experience,salary from junior) select * from final order by emp_id
@learner817
@learner817 8 месяцев назад
There should be a COALESCE to verify if the running sum for juniors is the total budget, the comparison for juniors wouldn't get evaluated due to NULL and hence the output wouldn't show any row even if the juniors were hired. where experience = 'Junior' and run_sal
@rahulmehla2014
@rahulmehla2014 3 месяца назад
with cte as( select *,sum(salary) over(order by salary) as sen_sal from candidates where experience = "Senior"), cte2 as( select *,max(sen_sal) over() as rem_budget from cte where sen_sal
@vikaskumar-qr5tj
@vikaskumar-qr5tj Год назад
Hi Ankit solved it using first_value and last_value window function plz have a look and tell if its ok or not:- With cte as ( Select *, first_value(recipientid) over(partition by callerid,cast(datecalled as date) order by datecalled) as first_day_call, last_value(recipientid) over(partition by callerid,cast(datecalled as date) order by datecalled rows between unbounded preceding and unbounded following) as last_day_call from phonelog ) Select distinct callerid,recipientid from cte where recipientid=first_day_call and recipientid=last_day_call;
@suriyas6338
@suriyas6338 Год назад
Hi Ankit, Please find my solution :) with rollingSum as ( select *, sum(salary) over(partition by experience order by salary asc rows between unbounded preceding and current row) as rolling_sum from candidates ) , seniorEmp as ( select * from rollingSum where rolling_sum < 70000 ), remainingAmount as ( select *, sum(rolling_sum) over(partition by experience) as balanceAmount from seniorEmp where experience = 'Senior' ) select distinct se.emp_id, se.experience, se.salary from seniorEmp se inner join remainingAmount ra on se.rolling_sum < ra.balanceAmount
@arpanscreations6954
@arpanscreations6954 2 месяца назад
Here is my solution: with cte as ( select * , sum(salary) over(partition by experience order by salary) as rolling_salary from candidates ) , cte2 as ( select *, sum(salary) over( order by (case when experience='Senior' then 0 else 1 end), rolling_salary) as rolling_salary2 from cte where rolling_salary
@user-xy8eh9he6f
@user-xy8eh9he6f 6 месяцев назад
with CTE AS ( select *, sum(salary) over(partition by experience order by salary) as running_sal from candidates ), CTE2 AS ( select *, row_number() over(order by running_sal desc) as seniors_tot_sal from CTE where experience='Senior' and running_sal
@sharu164
@sharu164 2 года назад
Thank you so much for the video and a wonderful explanation 😇
@RK-pi1kr
@RK-pi1kr 2 года назад
Btw you were telling about duplicate and use of unbound preceeding at end of vidoe. Could you please explain
@shwetadalal1549
@shwetadalal1549 Год назад
My Solution: ;with cte as ( select *,sum(salary) over(partition by experience order by emp_id) as RN from candidates ), cte2 as ( select * from cte where experience='Senior' and RN
@sureshboya8957
@sureshboya8957 2 года назад
Thanks you for good information giving
@shaikmahaboob4766
@shaikmahaboob4766 2 года назад
Hi Can you please make video on difference between group by and partition by
@ankitbansal6
@ankitbansal6 2 года назад
Here you go ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5Ighj_2PGV0.html
@shaikmahaboob4766
@shaikmahaboob4766 2 года назад
@@ankitbansal6 Thank you
@Datapassenger_prashant
@Datapassenger_prashant 4 месяца назад
with CTE as ( select *, case when sum(salary) over(partition by experience order by salary) < 70000 and experience ='Senior' then emp_id end as Senior_group from candidates), amount_used as ( Select Sum(salary) as Total_Used_Amount from CTE where Senior_group is not null), Cte2 as ( select *, case when sum(salary) over(partition by experience order by salary) < 70000 - (Select Total_used_amount from amount_used) and experience ='Junior' then emp_id end as junior_group from candidates) Select emp_id, experience, salary from Cte2 where Junior_Group is not Null union all select emp_id, experience, salary from CTE where Senior_group is not null
@Datapassenger_prashant
@Datapassenger_prashant 3 месяца назад
my revised solution after 3 weeks of practice : with running_salary as ( Select * ,sum(salary) over(partition by experience order by salary) as rn_sum from ms_candidates ), seniors_Hired as ( Select * from running_salary where rn_sum < 70000 and experience = 'Senior' ), rem_budget as ( Select 70000 - sum(salary) as Remaning_budget from seniors_Hired ) Select emp_id, experience, salary from running_salary where rn_sum < (select Remaning_budget from rem_budget) and experience = 'junior' union all Select emp_id, experience, salary from seniors_Hired;
@prashanthitirumala554
@prashanthitirumala554 2 года назад
Please do the videos on stored procedures
@Gabo4346dhdu
@Gabo4346dhdu Месяц назад
Great
@gijane2587
@gijane2587 2 года назад
Awesome one bro
@mayankbhardwaj1487
@mayankbhardwaj1487 2 года назад
Hi Ankit, first of all thanks a lot for the exclusive content you provide on your channel !! Tremendous job Here is my approach to the problem: with one as ( select *,sum(salary) over(partition by experience order by salary) as r_sum from candidates ), seniors as ( select * from one where experience='Senior' and r_sum
@ankitbansal6
@ankitbansal6 2 года назад
This is good but can be simplified a bit. Check out my solution.
@mayankbhardwaj1487
@mayankbhardwaj1487 2 года назад
@@ankitbansal6 your solutions are always best ❤️
@anish_bhateja
@anish_bhateja Год назад
with senior_candiates as (select *,sum(salary) over(order by salary) as rolling_sal from microsoft_candidates where experience = 'Senior'), selected_seniors as (select * from senior_candiates where rolling_sal
@arpitrai5736
@arpitrai5736 2 месяца назад
My Solution: with cte1 as (select *,sum(salary)over(partition by experience order by salary) as running_budget from candidates where experience='senior'),cte2 as (select *,rank()over(order by running_budget desc) as budget_rank from cte1 where running_budget
@nehabansal2618
@nehabansal2618 2 года назад
Great job 👍👍
@ankitbansal6
@ankitbansal6 2 года назад
Thank you 😊
@udayakumark1079
@udayakumark1079 4 месяца назад
with sen as(select emp_id,experience,salary,run from (select *,(sum(salary) over (order by salary)) as run from candidates where experience='senior') b where run jun as (select emp_id,experience,salary,run from (select *,(sum(salary) over (order by salary)) as run from candidates where experience='junior') a where (run+(select max(run) from sen)) select emp_id,experience,salary from jun union all select emp_id,experience,salary from sen;
@joeycopperson
@joeycopperson 2 года назад
this was good video
@ujjwalvarshney3188
@ujjwalvarshney3188 Год назад
create temp table uj as (select * from (select * , sum(salary) over (partition by experience order by salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as following_salary from candidates where experience = 'Senior') where following_salary < 70000); select emp_id,experience,salary from uj union all select emp_id,experience,salary from( select * , sum(salary) over (partition by experience order by salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as following_salary from candidates where experience = 'Junior') where following_salary < (select 70000 - max(following_salary) from uj)
@chickpeas6662
@chickpeas6662 2 года назад
Hi, thank you for the video, being honest I have never used aggregation with OVER functions as since DAX came out, this can be easily solved on the reporting side. Now, my question is very punctual. Would you recommend to run this in large datasets? How light is to apply this when you are talking about millions of rows?
@ankitbansal6
@ankitbansal6 2 года назад
It's quite optimised . You can run it on large data.
@nithinkumar6555
@nithinkumar6555 2 года назад
My Solution: with t1 as (select *,sum(salary) over(order by salary) as sm from candidates where experience='Senior'), t2 as (select emp_id,experience,salary from t1 where sm
@praveentanikella4078
@praveentanikella4078 2 года назад
Brother can you make a case study in SQL so that it will helpful like my other brothers who are interested. Thanks
@kirangadhe4962
@kirangadhe4962 Год назад
;with cte as ( SELECT *, sum(salary) over(order by salary rows between unbounded preceding and current row) as rol_sum from candidates where experience = 'Senior' ), cte1 as (SELECT 70000- sum(salary) as rem from cte where rol_sum
@innominatesoloist1597
@innominatesoloist1597 2 года назад
brilliant
@lakshaykhanna2462
@lakshaykhanna2462 7 месяцев назад
WITH cte AS ( SELECT *, SUM(salary) OVER(PARTITION BY experience ORDER BY salary) AS r_spent FROM candidates ) SELECT * FROM cte WHERE r_spent
@sakshinaik05
@sakshinaik05 2 года назад
Question was interesting but bit tricky
@ankitbansal6
@ankitbansal6 2 года назад
Yup
@maverick6932
@maverick6932 2 года назад
Solution: ===================== with cte1(emp_id,experience,salary,rolling_sum) as (select emp_id , experience ,salary , sum(salary) over(order by salary asc rows between 6 preceding and 0 following) as rolling_sum from candidates where experience = 'Senior'), cte2 as ( select emp_id , experience , salary from cte1 where rolling_sum
@Alexpudow
@Alexpudow 6 месяцев назад
with a as ( select *, min(df) over() budget_2 from ( select *, 70000 - sum(salary) over(order by salary, emp_id) df from candidates where experience = 'Senior') t where df >=0 ) select emp_id, experience, salary from ( select *, (select min(budget_2) from a) - sum(salary) over(order by salary, emp_id) df from candidates c where experience = 'Junior') t where df>=0 union select emp_id, experience, salary from a
@HARSHRAJ-wz2rp
@HARSHRAJ-wz2rp 26 дней назад
with cte as( select candidates.*,SUM(salary)OVER(PARTITION BY experience ORDER BY salary) as es FROM candidates ),cte1 as( select emp_id,experience,salary,es FROM cte where es
@awaise92
@awaise92 2 года назад
HI Ankit, I would like to know if there are any python modules in particular to prepare for a data engineer role.. Thanks
@perumala4167
@perumala4167 2 года назад
I have tried like below and not sure its optimized with cte1 as ( select *,Sum(Salary) over (partition by experience order by salary) as RT from candidates) , cte2 as( select c1.*,max(c2.rt) as rt2,c1.rt+max(c2.rt) as Total from cte1 c1 left join cte1 as c2 on c2.experience='Senior' and c2.rt
@ankitbansal6
@ankitbansal6 2 года назад
Looks fine. Can be made simple. Check out my solution
@saiswaroop3570
@saiswaroop3570 6 месяцев назад
with cte1 as ( select emp_id,salary,experience from ( select emp_id, experience, salary, sum(salary)over(partition by experience order by salary asc) roll_sum, dense_rank()over(partition by experience order by salary asc) rnk from candidates order by emp_id ) where experience = 'Senior' and roll_sum
@shami621
@shami621 2 года назад
We can also achieve this output by using temp table Am i right?
@lakshitsharma5533
@lakshitsharma5533 2 года назад
Hi Ankit, Solution dekhke to asaan lgta hai..but khud try krta hu to nahi hota. Please help..kaise kru SQL strong so that I dont have to see solutions
@ankitbansal6
@ankitbansal6 2 года назад
You need to give 2-3 attempts without looking at the solution. After that you can check the solution and compare ..
@subimalkhatua2886
@subimalkhatua2886 2 года назад
with cte as ( select emp_id , experience,salary , sum(salary) over(partition by experience order by salary) as total_salary_sum from candidates ) , cte1 as ( select emp_id, experience ,salary,total_salary_sum from cte where total_salary_sum < 70000 and experience = 'Senior' ), cte2 as ( select emp_id,experience, salary From cte where total_salary_sum < 70000-(select max(total_salary_sum) from cte1 ) and experience = 'Junior') select * from cte2 union select emp_id, experience ,salary from cte1;
@ankitbansal6
@ankitbansal6 2 года назад
Good one 👍
@ayushi_patra
@ayushi_patra 9 месяцев назад
with senior_hires as ( select emp_id, experience, salary, rsum from ( select emp_id, experience, salary, sum(salary) over (order by salary) as rsum from candidates where experience = 'Senior' ) where rsum
@enisertem9738
@enisertem9738 11 месяцев назад
with s as (select *,Sum(salary) over (order by experience desc,salary asc) running_sum from candidates where experience ='Senior') ,l as ( select emp_id,experience,salary,sum(salary) over (order by experience desc,salary asc) rs from ( select * from s where running_sum
@kasmitharam982
@kasmitharam982 Год назад
This is my solution: WITH CTE1 AS ( SELECT emp_id, experience,senior_sum as salaries FROM (SELECT *, sum(salary) over (partition by experience order by salary) as senior_sum from candidates WHERE experience = 'Senior') AS e WHERE senior_sum < 70000), CTE2 AS ( SELECT emp_id, experience,junior_sum as salaries FROM (SELECT *, sum(salary) over (partition by experience order by salary) as junior_sum from candidates WHERE experience = 'Junior') AS e WHERE junior_sum < (SELECT salaries FROM CTE1 ORDER BY SALARIES DESC LIMIT 1)) SELECT * FROM CTE1 UNION SELECT * FROM CTE2;
@SuperMohit95
@SuperMohit95 2 года назад
I was trying to play around in SQL and getting a syntax error here. Could anyone tell me the issue here pls WITH cte AS ( SELECT *, SUM(salary) OVER(PARTITION BY experience ORDER BY salary ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS sum_sal FROM candidates_sep ), seniors AS (SELECT * FROM cte WHERE experience = 'Senior' AND sum_sal
@ankitbansal6
@ankitbansal6 2 года назад
All are ctes . You need to write last select
@himanshibansal336
@himanshibansal336 2 года назад
👍👍
@Dhanushts-g7x
@Dhanushts-g7x Год назад
with cte1 as (select *,70000-max(cum_sum) over() remain from (select *,sum(salary) over(order by salary) cum_sum from candidates where experience="senior") a where cum_sum
@vijaypalmanit
@vijaypalmanit 2 года назад
Bhai bhai bhai 👨
@ankitbansal6
@ankitbansal6 2 года назад
Bhai bhai
@akelakela5524
@akelakela5524 Год назад
WITH cte AS ( SELECT *, SUM(salary) OVER(PARTITION BY experience ORDER BY salary) AS cf FROM candidates ) , Senior AS ( SELECT emp_id,experience,salary FROM cte WHERE cf
@meetpatel.47
@meetpatel.47 8 месяцев назад
How many hacker rank dsa questions should do for fresher data engineer at faang?
@ankitbansal6
@ankitbansal6 8 месяцев назад
Basic level only
@meetpatel.47
@meetpatel.47 8 месяцев назад
@@ankitbansal6 and for sqql?
@ankitbansal6
@ankitbansal6 8 месяцев назад
@@meetpatel.47 advanced level
@meetpatel.47
@meetpatel.47 8 месяцев назад
@@ankitbansal6 binary trees also in sql?
@bollytalkies8026
@bollytalkies8026 Год назад
100%
@vivekpuurkayastha1580
@vivekpuurkayastha1580 2 года назад
your answer is wrong .... at 7:58 there are 4 employees 2 senioprs and 2 juniors with total salry coming to be 87000 (10k + 25k + 16k + 36k) ... the answer should not contain the guy with 25k salary and that totals to 62k then ... Find the below code for the same ... I have used Postgres WITH total_budget AS ( SELECT 70000 ) , running_sals AS ( SELECT emp_id, experience, salary , SUM(salary) OVER( PARTITION BY experience ORDER BY salary ASC, emp_id ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS running_sal FROM candidates ) , seniors AS ( SELECT * FROM running_sals WHERE experience='Senior' AND running_sal
@ankitbansal6
@ankitbansal6 2 года назад
You are looking at the running sum column. Check the salary column..
@vivekpuurkayastha1580
@vivekpuurkayastha1580 2 года назад
@@ankitbansal6 Yeah, sorry about that ... I went through it late at night and thus was not sharp enough.... Please remove the comment thread.. Thanks
@anirvansen2941
@anirvansen2941 Год назад
HI , I have tried to use Recursive CTE approach IN MYSQL for my learning with recursive base as (select *,rank() over (partition by experience order by salary asc) as rnk_within from candidates) ,base_senior_recruitment as ( select emp_id,salary,experience,salary as budget, rnk_within as rnk from base where experience = 'Senior' and rnk_within = 1 UNION ALL select t2.emp_id,t2.salary,t2.experience,t1.budget + t2.salary as budget,t2.rnk_within as rnk from base_senior_recruitment t1 join base t2 on t2.rnk_within = t1.rnk+1 and t1.budget + t2.salary < 70000 and t2.experience = 'Senior' and t1.emp_id != t2.emp_id ), budget_left as ( select 76000 - sum(salary) as budget_left from base_senior_recruitment ), base_junior_recruitment as ( select emp_id,salary,experience,budget_left - salary as left_money, rnk_within as rnk from base,budget_left where experience = 'Junior' and rnk_within = 1 and salary < budget_left UNION ALL select t2.emp_id,t2.salary,t2.experience,t1.left_money - t2.salary as left_money,t2.rnk_within as rnk from base_junior_recruitment t1 join base t2 on t2.rnk_within = t1.rnk+1 and t2.salary < t1.left_money and t2.experience = 'Junior' and t1.emp_id != t2.emp_id ) select emp_id,salary,experience from base_senior_recruitment UNION ALL select emp_id,salary,experience from base_junior_recruitment
@mananagrawal4114
@mananagrawal4114 3 месяца назад
Here is my solution to above problem: with cte as( SELECT *, sum(salary) over (Partition by experience order by salary) as rolling_sum from candidates ), cte2 as( SELECT *, 70000-sum(salary) over (Partition by experience) as rem_salary FROM cte where rolling_sum
@sandeepanand3834
@sandeepanand3834 21 день назад
my solution with watching yours with cte_s1 as( select *, sum(salary) over(order by salary asc) as senior_sal_cum from candidates where experience = 'Senior' order by salary asc ), cte_j1 as( select *, sum(salary) over(order by salary asc) as junior_sal_cum from candidates where experience = 'Junior' order by salary asc ) select emp_id, experience, salary from cte_s1 where senior_sal_cum
@antonispanagopoulos75
@antonispanagopoulos75 2 года назад
WITH cands AS ( SELECT e.emp_id,e.salary,e.experience,e.SumCumulative,MAX(e.BudgetRemainder) OVER () AS BudgetRemainder FROM ( SELECT t.emp_id,t.salary,t.experience,t.SumCumulative,70000-MAX(t.SumCumulative) OVER() AS BudgetRemainder FROM ( SELECT c.emp_id, c.salary, c.experience, SUM(c.salary) OVER(PARTITION BY c.experience ORDER BY (SELECT NULL) ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS SumCumulative FROM candidates c WHERE 1=1 AND c.experience='Senior' ) t WHERE 1=1 AND t.SumCumulative
@ankitbansal6
@ankitbansal6 2 года назад
Appreciate your efforts. The solution can be simplified a bit. Check out my solution..
Далее
Добрая весть 😂
00:21
Просмотров 398 тыс.
Dora was kidnapped and then… 😨 #shorts
00:18
Просмотров 2,4 млн
SQL Interview Question Asked in Tredence Analytics
15:27
Zepto Product Analyst SQL Interview Question
13:59
Просмотров 10 тыс.
Apple Event - September 9
1:38:50
Просмотров 26 млн
Вредно ли не выключать ПК?
0:43
Просмотров 253 тыс.