3 Very Important SQL Interview Questions on LeetCode | Practise SQL Questions
Вставка
- Опубліковано 16 вер 2024
- 𝐖𝐚𝐧𝐭 𝐭𝐨 𝐌𝐚𝐬𝐭𝐞𝐫 𝐒𝐐𝐋? 𝐋𝐞𝐚𝐫𝐧 𝐒𝐐𝐋 𝐭𝐡𝐞 𝐫𝐢𝐠𝐡𝐭 𝐰𝐚𝐲 𝐭𝐡𝐫𝐨𝐮𝐠𝐡 𝐭𝐡𝐞 𝐦𝐨𝐬𝐭 𝐬𝐨𝐮𝐠𝐡𝐭 𝐚𝐟𝐭𝐞𝐫 𝐜𝐨𝐮𝐫𝐬𝐞 - 𝐒𝐐𝐋 𝐂𝐡𝐚𝐦𝐩𝐢𝐨𝐧𝐬 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐛𝐲 𝐒𝐮𝐦𝐢𝐭 𝐒𝐢𝐫!
"𝐀 8 𝐰𝐞𝐞𝐤 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐝𝐞𝐬𝐢𝐠𝐧𝐞𝐝 𝐭𝐨 𝐡𝐞𝐥𝐩 𝐲𝐨𝐮 𝐜𝐫𝐚𝐜𝐤 𝐭𝐡𝐞 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰𝐬 𝐨𝐟 𝐭𝐨𝐩 𝐩𝐫𝐨𝐝𝐮𝐜𝐭 𝐛𝐚𝐬𝐞𝐝 𝐜𝐨𝐦𝐩𝐚𝐧𝐢𝐞𝐬 𝐛𝐲 𝐝𝐞𝐯𝐞𝐥𝐨𝐩𝐢𝐧𝐠 𝐚 𝐭𝐡𝐨𝐮𝐠𝐡𝐭 𝐩𝐫𝐨𝐜𝐞𝐬𝐬 𝐚𝐧𝐝 𝐚𝐧 𝐚𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐭𝐨 𝐬𝐨𝐥𝐯𝐞 𝐚𝐧 𝐮𝐧𝐬𝐞𝐞𝐧 𝐏𝐫𝐨𝐛𝐥𝐞𝐦."
𝐇𝐞𝐫𝐞 𝐢𝐬 𝐡𝐨𝐰 𝐲𝐨𝐮 𝐜𝐚𝐧 𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐟𝐨𝐫 𝐭𝐡𝐞 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 -
𝐑𝐞𝐠𝐢𝐬𝐭𝐫𝐚𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 (𝐂𝐨𝐮𝐫𝐬𝐞 𝐀𝐜𝐜𝐞𝐬𝐬 𝐟𝐫𝐨𝐦 𝐈𝐧𝐝𝐢𝐚) : rzp.io/l/SQLINR
𝐑𝐞𝐠𝐢𝐬𝐭𝐫𝐚𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 (𝐂𝐨𝐮𝐫𝐬𝐞 𝐀𝐜𝐜𝐞𝐬𝐬 𝐟𝐫𝐨𝐦 𝐨𝐮𝐭𝐬𝐢𝐝𝐞 𝐈𝐧𝐝𝐢𝐚) : rzp.io/l/SQLUSD
𝐖𝐚𝐧𝐭 𝐭𝐨 𝐥𝐞𝐚𝐫𝐧 𝐁𝐢𝐠 𝐃𝐚𝐭𝐚 𝐛𝐲 𝐒𝐮𝐦𝐢𝐭 𝐒𝐢𝐫?
𝐜𝐡𝐞𝐜𝐤𝐨𝐮𝐭 𝐭𝐡𝐞 𝐛𝐢𝐠 𝐝𝐚𝐭𝐚 𝐜𝐨𝐮𝐫𝐬𝐞 𝐝𝐞𝐭𝐚𝐢𝐥𝐬
𝐖𝐞𝐛𝐬𝐢𝐭𝐞 : trendytech.in/...
I have trained over 20,000+ professionals in the field of Data Engineering in the last 5 years.
3 Very Important SQL Interview Questions on LeetCode | Practise SQL Questions
178. Rank Scores
180. Consecutive Numbers
181. Employees Earning More Than Their Managers
Do Like, Comment & Subscribe ..
𝗝𝗼𝗶𝗻 𝗺𝗲 𝗼𝗻 𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:🔥
🔅Sumit LinkedIn - / bigdatabysumit
🔅Sumit Instagram - / bigdatabysumit
In this video, we will solve SQL question on LeetCode. LeetCode is an excellent platform for practicing SQL Queries. The SQL Questions on LeetCode are framed pretty similar to how they are asked on SQL Interviews hence solving SQL questions on LeetCode can give you a good hands on experience on solving real world SQL questions.
#SQL #RDBMS #database #bigdata #dataengineering
Checkout the Big Data course details here: trendytech.in/?referrer=youtube_lc3
Thanks Sumit sir for such wonderful content and resolution. I have tried to resolve the problem-180 (Consecutive Numbers )with CTE and window function on my own and this is my 2 cents on it :
with consecutive_val (num,next_val,next_to_next_val) as
(select num , (lead(num,1) over (order by id asc)) as next_val , (lead(num,2) over (order by id asc)) as next_to_next_val
from Logs)
select distinct num as ConsecutiveNums from consecutive_val
where num=next_val
and num=next_to_next_val
That is nice. Keep practicing and improving on your skills
@@sumitmittal07 Thanks a lot for all the motivation.
Thanks for these videos sir.
for 180 this is another way of doing
with cte as (
select *, lead(val) over(order by id) 'nextval', lead(val,2) over(order by id) '2nd next val' from #test
)
select distinct [2nd next val] from cte where val = nextval and val = [2nd next val]
These videos are very helpful in getting clarity on such topics also this will help to crack interviews in the top IT firms. Thank you very much Sumit sir.
I am happy that you are finding it helpful!
able to understand when to use self-join & how to use self-join practically, SQL looks very interesting now, thank you very much sir :)
Hi sumit sir ..nice video..
Just 1 question in problem number 180..what if we have string value instead of integers for ID column...please reply..
Thanks for uploading...
Waiting for next one
Will be uploaded soon!
select num as ConsecutiveNums from( SELECT num,row_number() OVER (PARTITION BY num) as cu FROM Logs) where cu>=3; does this work for second problem?
love to watch your videos!!
I'm so glad you are loving the videos.
Very helpful to this video
Thank you sumit for such useful videos
For Q.180. Can’t we use Row Number partition by num, order by num and select Row Number > = 3??
select num as ConsecutiveNums from( SELECT num,row_number() OVER (PARTITION BY num) as cu FROM Logs) where cu>=3;
For problem-180 (Consecutive Numbers ) - I have used LEAD function.
select
distinct num as ConsecutiveNums
from
(select num,
LEAD(num, 1) OVER (ORDER BY id) as lead_1,
LEAD(num, 2) OVER (ORDER BY id) as lead_2
from Logs) as temp
where
temp.num=temp.lead_1 and temp.num=temp.lead_2
lovely sumit sir
Thank you Mubashir :)
I have one doubt here in problem statement 180. Consecutive Numbers. I understand we need to compare the ids in the join operation. But how is the = operator working. if logs l1 and l2 are pointing to same table,l1.id how is l1.id=l2.id+1 . isn't it comparing 1=2 in first case ? Will it not fail?
Same doubt i have
Thank you sir...
the second problem where you added 1 and 2 was quite confusing.
plz solve more videos sir
it tried this way to get number which are repeting 3 time.
-- create
CREATE TABLE EMPLOYEE (
id INTEGER PRIMARY KEY,
number INTEGER NOT Null
);
-- insert
INSERT INTO EMPLOYEE VALUES (1,1);
INSERT INTO EMPLOYEE VALUES (2,1);
INSERT INTO EMPLOYEE VALUES (3,1);
INSERT INTO EMPLOYEE VALUES (4,2);
INSERT INTO EMPLOYEE VALUES (5,2);
INSERT INTO EMPLOYEE VALUES (6,3);
INSERT INTO EMPLOYEE VALUES (7,3);
-- fetch
select t.number,count(t.number) from
(select id,number,rank() over(order by id,number) as 'rank' from EMPLOYEE) t
group by t.number
having count(t.number)=3
Sir what about java please make video on java interview
179 :
SELECT s.score, DENSE_RANK() OVER(ORDER BY score DESC) AS rank
FROM scores s
ORDER BY s.score DESC;
181:select
E.name as employee
from employee E
where E.managerid is not null
and E.salary > (select t1.salary from employee t1 where E.managerId = t1.id);
Sir how to join your session
Are these for beginners or for the ones with 1-2 years of experience ?