LEAD & LAG in SQL | Analytical Functions Advanced SQL | Ashutosh Kumar

preview_player
Показать описание
Sql one of the most important language asked in most of the analytics interviews,in this series i have discussed some advanced level sql concepts that are frequently asked in data analyst,business analyst interviews. In this video i have covered lead lag functions concepts in sql which comes in window functions.

👉 Link to excel file -

#code for 1st table

drop table if exists details;
CREATE TABLE details(train_no INT, station VARCHAR(200), Timing TIME);

INSERT INTO details(train_no , station , Timing)
VALUES(22863,'Howrah','10:50:00'),
(22863 ,'Kharagpur','12:30:00'),
(22863 ,'Balasore','13:52:00'),
(22863 ,'Cuttack','15:47:00'),
(22863 ,'Bhubaneswar','16:25:00'),
(12262 ,'Howrah','05:45:00'),
(12262 ,'Tatanagar','09:00:00'),
(12262 ,'Bilaspur','15:05:00'),
(12262 ,'Raipur','16:37:00'),
(12262 ,'Nagpur','20:55:00');

select * from details;

👉 Complete playlist on Sql Interview questions and answers

---------------------------------------------------------------------------------------------------------------------
Check out some more relevant content here

👉 How to Learn SQL

👉 How to become a business analyst complete roadmap-

👉 How to become a data analyst complete roadmap-

👉 Top 3 you tube channels to learn sql for free for beginners

👉 Rank ,Dense Rank, Row Number in sql -

👉 Cross join in sql

👉 union join in sql

👉 left join in sql

👉 Right join in sql

👉 Inner join in sql

👉 Introduction to tables and databases in sql -

👉 Aggregate Function in sql

👉 Functions in sql-

👉 String Function in sql

👉 CRUD operations in sql

👉 Autoincrement in sql

👉 Primary Key in sql-

👉 Null and Default values in sql-

👉 Data types in sql-

____________________________________________________________________

_______________________________________________________________________
Connect with me

_____________________________________________________________________

Comment down if you have any doubts
Please leave a LIKE 👍 and SUBSCRIBE ❤️ to my channel to receive more amazing content in data analytics and data science.

_____________________________________________________________________

🏷️ Tags

sql,
sql for data science,
sql for data analytics,
sql practise questions,
sql practise questions and solutions,
sql tutorials for beginners,
sql problems for data engineers,
ashutosh,
ashutosh kumar,
ashutosh kumar analytics,
sql problems easy,
sql problem medium,
sql problems hard,
sql window functions,
sql advanced questions,
rank functions in sql,
lag lead in sql,
sql interview questions and answers,
sql interview questions,
sql questions asked in interviews,
hackerrank sql solutions,
hackerearth sql solutions,
leetcode sql solution

🏷️HashTags

#sql #interviews #questions #solutions
Рекомендации по теме
Комментарии
Автор

Great learning thanks
I tried to use this query
for Q-3
select name, count(prevyr) as summ from(
select name, years, run, lag(run) over(partition by name order by years)-run as prevyr
from runs)a
where prevyr<0
group by name

ashutoshverma
Автор

you are putting a lot of effort to taught us..kudos to you dear..god bless you with health and wealth...

vijaykrishnachari
Автор

Bro ek hi baat bolunga yaar
Ki aap kitni tassali se padhate ho, ek ek concept clear ho gya!
Bro, You are jam ♥️

Gurjar
Автор

SELECT TIMEDIFF(end_time_column, start_time_column) AS time_difference
FROM your_table;
use this from getting difference

onkarjoshi
Автор

👉 SQL Portfolio Project Indian Census- Part 1
👉 Advanced Sql Concepts Complete Playlist

AshutoshKumaryt
Автор

BHT SAHI H SIR...ADVANCE EXCEL KA BHI PADHA DIJIYE SIR PLS

mcdolla
Автор

Thanks for the clear Explanation bro..

analyticstamizan
Автор

Hi Ashutosh, first of all this is great series.
Thank you so much for guiding us.
I want to ask one question, As given in the last question that fetch those queries where the runs have been increased for the continuously 3 years. If 5 was given in place of 3, So how can we write the query to find those runs whose are increasingly continuously by 5 years? Looking forward to hear from you! Thanks in advance.

gargshashank
Автор

try to write query in a way that it will be completely visible, at present only half query is visible, it is difficult to understand it in one go.

smonica
Автор

in mysql it's timediff(t1, t2)

harshkhola
Автор

We can also do that through self join right?

kusummishra
Автор

Hi Ashutosh
Thank you for sharing such videos.
Wanted to ask why ain’t we using rows between function while calculating lead values. As you mentioned in the previous videos that we need to use rows between function when we use partition by. Please clarify

SoniaMalhotra-ix
Автор

what about the year 2008 for which Rohit has scored more runs than in year 2009,

vishvadeepmohanpandey
Автор

I'm searching for that particular video but struggling to find it. It will be great if you could explain that calculation in this video only. Video would be 10 mins lengthy but this would be a great video had you included the content of that particular video

kishanbhise
Автор

Hi bro excellent content, ...but am unable to download the xlsx file from the github link!!! can you pls look into this

sabyasachiojha
Автор

please provide the link for the cricket dataset. I am unable to find

SandipanSarkar-cv
Автор

sir in this train timing analysis, i thought of some issue...c you did min of time so yu r getting oldest time of the table, but what when the train is being travelling over nights, then dates changes so will it work then?, in pandas by using date time package that can be figured out anyway, but how to tackle that in sql.. kindly reply, if possible

s.m.shreyas
Автор

hii sir
the code written at 12:18 is not shown full, and also in time difference video full code is not covered, what all are that floor, %86400 and nested query.
i didnt get it fully

Shikimori-kwxq
Автор

Bro we can use TimeDiff() function for 2)elapse time till now.

priya-ybmh
Автор

where is the video for time difference?plz send me the link?

sarthaksatapathy