3 Very Important SQL Interview Questions on LeetCode | Practise SQL Questions

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
๐–๐š๐ง๐ญ ๐ญ๐จ ๐Œ๐š๐ฌ๐ญ๐ž๐ซ ๐’๐๐‹? ๐‹๐ž๐š๐ซ๐ง ๐’๐๐‹ ๐ญ๐ก๐ž ๐ซ๐ข๐ ๐ก๐ญ ๐ฐ๐š๐ฒ ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก ๐ญ๐ก๐ž ๐ฆ๐จ๐ฌ๐ญ ๐ฌ๐จ๐ฎ๐ ๐ก๐ญ ๐š๐Ÿ๐ญ๐ž๐ซ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž - ๐’๐๐‹ ๐‚๐ก๐š๐ฆ๐ฉ๐ข๐จ๐ง๐ฌ ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ!

"๐€ 8 ๐ฐ๐ž๐ž๐ค ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐๐ž๐ฌ๐ข๐ ๐ง๐ž๐ ๐ญ๐จ ๐ก๐ž๐ฅ๐ฉ ๐ฒ๐จ๐ฎ ๐œ๐ซ๐š๐œ๐ค ๐ญ๐ก๐ž ๐ข๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ๐ฌ ๐จ๐Ÿ ๐ญ๐จ๐ฉ ๐ฉ๐ซ๐จ๐๐ฎ๐œ๐ญ ๐›๐š๐ฌ๐ž๐ ๐œ๐จ๐ฆ๐ฉ๐š๐ง๐ข๐ž๐ฌ ๐›๐ฒ ๐๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ข๐ง๐  ๐š ๐ญ๐ก๐จ๐ฎ๐ ๐ก๐ญ ๐ฉ๐ซ๐จ๐œ๐ž๐ฌ๐ฌ ๐š๐ง๐ ๐š๐ง ๐š๐ฉ๐ฉ๐ซ๐จ๐š๐œ๐ก ๐ญ๐จ ๐ฌ๐จ๐ฅ๐ฏ๐ž ๐š๐ง ๐ฎ๐ง๐ฌ๐ž๐ž๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ."

๐‡๐ž๐ซ๐ž ๐ข๐ฌ ๐ก๐จ๐ฐ ๐ฒ๐จ๐ฎ ๐œ๐š๐ง ๐ซ๐ž๐ ๐ข๐ฌ๐ญ๐ž๐ซ ๐Ÿ๐จ๐ซ ๐ญ๐ก๐ž ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ -

๐–๐š๐ง๐ญ ๐ญ๐จ ๐ฅ๐ž๐š๐ซ๐ง ๐๐ข๐  ๐ƒ๐š๐ญ๐š ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ?
๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ ๐ญ๐ก๐ž ๐›๐ข๐  ๐๐š๐ญ๐š ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž ๐๐ž๐ญ๐š๐ข๐ฅ๐ฌ

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 ..

๐—๐—ผ๐—ถ๐—ป ๐—บ๐—ฒ ๐—ผ๐—ป ๐—ฆ๐—ผ๐—ฐ๐—ถ๐—ฎ๐—น ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ:๐Ÿ”ฅ

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
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

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

rajorshi
ะะฒั‚ะพั€

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]

mystuffstudy
ะะฒั‚ะพั€

able to understand when to use self-join & how to use self-join practically, SQL looks very interesting now, thank you very much sir :)

arunsundar
ะะฒั‚ะพั€

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.

swastiktripathy
ะะฒั‚ะพั€

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..

dineshchavan
ะะฒั‚ะพั€

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?

girih-ytde
ะะฒั‚ะพั€

Thanks for uploading...
Waiting for next one

mallikarjunpatil
ะะฒั‚ะพั€

Thank you sumit for such useful videos

technicalknowledge
ะะฒั‚ะพั€

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

satishraj
ะะฒั‚ะพั€

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

santoshingle
ะะฒั‚ะพั€

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?

shivangikhanna
ะะฒั‚ะพั€

For Q.180. Canโ€™t we use Row Number partition by num, order by num and select Row Number > = 3??

mukeshrajpurohit
ะะฒั‚ะพั€

the second problem where you added 1 and 2 was quite confusing.

karthikbs
ะะฒั‚ะพั€

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);

kishorekunal
ะะฒั‚ะพั€

Sir what about java please make video on java interview

kiran
ะะฒั‚ะพั€

Are these for beginners or for the ones with 1-2 years of experience ?

sandeepmanjunath