Lead/Lag Window Analytical functions in SQL | Advance SQL concepts

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • In this video we will learn lead/lag analytical functions. these functions are used when you need to compare current row with another previous or next row. Very important for interview preparation as well.

ความคิดเห็น • 70

  • @abhisheknigam3768
    @abhisheknigam3768 24 วันที่ผ่านมา

    After watching your videos i can say that " Interview khi se bhi ho kha ka bhi ho ghanta fark nhi padta " . I faced similar questions and also questions from joins operation. I successfully solved it in sql interview. 🙏.Thank you

  • @rks.siddhartha
    @rks.siddhartha 2 ปีที่แล้ว +7

    I always get confused with the combination of lead/lag and order by in the over clause which lead to couple of tries to get the desired output, faced similar confusion today and searched your channel for the these functions. Thank you for covering exactly what I was looking for!!

  • @ianpropst-campbell6028
    @ianpropst-campbell6028 2 ปีที่แล้ว +2

    This was a helpful demonstration of the lead and lag functions. Thank you!

  • @Bhagwatbhograsoi
    @Bhagwatbhograsoi ปีที่แล้ว +2

    That's the best explanation I found on lead and lag, thanks bro

  • @lokeshsharma9386
    @lokeshsharma9386 ปีที่แล้ว

    Thank you, I have got a job with 50% , I have learnt virtually from your videos, my concept got clear . Thank you so much

  • @learnwithAashish
    @learnwithAashish 2 ปีที่แล้ว +4

    Thanks for your valuable knowledge Sharing. Although I learned SQL but everytime I came here , always feel I know nothing.
    Keep Good work going 👍 & also if possible please start sharing your knowledge on Python it will be very helpful.
    Thanks

  • @adityeshchaturvedi6553
    @adityeshchaturvedi6553 2 ปีที่แล้ว +2

    Short crisp and really informative!

  • @shubhammeshram8504
    @shubhammeshram8504 7 หลายเดือนก่อน +1

    Great. Very informative 😀.

  • @AjayVyas-h6k
    @AjayVyas-h6k หลายเดือนก่อน

    Very good explanantion

  • @mantisbrains
    @mantisbrains หลายเดือนก่อน

    Thank you,Ankit. very useful!

  • @amitkushwah8401
    @amitkushwah8401 ปีที่แล้ว

    Really Good. Explained in the simplest way.

  • @dfkgjdflkg
    @dfkgjdflkg 8 หลายเดือนก่อน

    As usual, great content. Excellent work. thank you

  • @sharans5771
    @sharans5771 4 หลายเดือนก่อน

    Excellent explanation, especially with real time scenario example

    • @ankitbansal6
      @ankitbansal6  4 หลายเดือนก่อน

      Glad it was helpful!

  • @jannatbhengray1650
    @jannatbhengray1650 2 หลายเดือนก่อน +1

    Thank you so much, it made my topic crystal clear :-)

  • @abhisheknigam3768
    @abhisheknigam3768 26 วันที่ผ่านมา

    Can we get more interview questions on lag and lead with window function. Like there are two tables employees id with x and employees id with y then find employee who are doing work from home 3 days continuously.

  • @minlin9705
    @minlin9705 2 ปีที่แล้ว

    It is well explained. The example is aweomse. Thank you, Ankit!!

  • @mdfurqan
    @mdfurqan ปีที่แล้ว +1

    Hi Ankit,
    I am using history table where create_dt is the indicator for comparison between 2 rows, I have used this lag logic to generate scd2 on my history table. Thanks

    • @apexemperor
      @apexemperor ปีที่แล้ว

      Hi... I am also probably looking for the same thing . I have a table which has Scd2 records and the last active records ends with high end dt something like 2200-01-01
      Do u think this logic will work with some twigs ofcourse?

    • @mdfurqan
      @mdfurqan ปีที่แล้ว +1

      @@apexemperor yes have implemented and working fine

  • @gyan_chakra
    @gyan_chakra 2 ปีที่แล้ว

    Awesome 😎👍.. such a lovely & simple explanation 😊

  • @vikasvk9174
    @vikasvk9174 2 ปีที่แล้ว

    very informative video ... Thank you

  • @DishantGupta-t
    @DishantGupta-t 4 หลายเดือนก่อน

    Helpful 👍

    • @ankitbansal6
      @ankitbansal6  4 หลายเดือนก่อน

      Glad it helped

  • @mehmetkaya4330
    @mehmetkaya4330 ปีที่แล้ว

    Thank you for the great examples!

  • @shankrukulkarni3234
    @shankrukulkarni3234 ปีที่แล้ว +1

    It really good if you can provide the dataset link so that we can practice simultaniously

    • @dfkgjdflkg
      @dfkgjdflkg 8 หลายเดือนก่อน

      Look online, lots of datasets

  • @sivasuthan004
    @sivasuthan004 2 ปีที่แล้ว

    Crisp and clear explanation!

  • @sreedharagandla
    @sreedharagandla หลายเดือนก่อน

    Hi ankit ,
    Can u let me know super data where it is or can share the link pls so that we can prasctise .
    Thanks

  • @PhysicsCoachAnkitSaraswat
    @PhysicsCoachAnkitSaraswat ปีที่แล้ว

    do bring some more example question related to sql topics and provide data shert for practvie sir

  • @god_father007i
    @god_father007i 7 หลายเดือนก่อน

    Thanks men it helps

  • @vikastyagi7811
    @vikastyagi7811 2 ปีที่แล้ว

    Crisp and clear

  • @shifanasheriff
    @shifanasheriff 2 ปีที่แล้ว

    Hi Ankit ,
    What change should do in the query
    If I want to see the sales of same period last year till the date
    (YTD previous year)? Can you help ?

    • @pavan5208
      @pavan5208 ปีที่แล้ว

      Create a YTD Flag first and use that as a filter?

  • @gazart8557
    @gazart8557 ปีที่แล้ว

    Excellent

  • @pavankumarchahar
    @pavankumarchahar ปีที่แล้ว

    Suppose we have the YEAR, Revenue column but the year is 2012, 2015, 2016, 2017, and 2019 then this case how to calculate the missing default year 0 and subsequent.

  • @ankush_in_sync5998
    @ankush_in_sync5998 3 หลายเดือนก่อน

    Love you sir, love you

  • @anirudhupadhyay695
    @anirudhupadhyay695 2 ปีที่แล้ว

    Congratulations and thanks.

  • @pavitrashailaja850
    @pavitrashailaja850 2 ปีที่แล้ว

    Very neatly explained!

  • @apexemperor
    @apexemperor ปีที่แล้ว +1

    Hi... I am also probably looking for the same thing . I have a table which has Scd2 records and the last active records ends with high end dt something like 2200-01-01
    Do u think this logic will work with some twigs ofcourse?
    Came across your channel yesterday and there are lot of things to learn ❤

    • @ankitbansal6
      @ankitbansal6  ปีที่แล้ว +1

      What exactly do you want to achieve from your scd2 table ?

  • @D-InFluencer4u
    @D-InFluencer4u 5 วันที่ผ่านมา

    It is basically current vs previous year comparison

  • @ritikajaiswal3824
    @ritikajaiswal3824 2 ปีที่แล้ว

    Can you make a video on the code which is different in different database like oracle, mysql workbench, postgresql, ms server?

  • @Jessicaladyjuno
    @Jessicaladyjuno 2 ปีที่แล้ว +1

    Please provide the create and insert query so that we can practice

    • @ankitbansal6
      @ankitbansal6  2 ปีที่แล้ว

      Rashi scripts are there in most the videos description box. Will fix if anyone is missing

    • @Jessicaladyjuno
      @Jessicaladyjuno 2 ปีที่แล้ว

      @@ankitbansal6 can you let me know in which video you have imported the data or share the link I cant find it

    • @ankitbansal6
      @ankitbansal6  2 ปีที่แล้ว

      @@Jessicaladyjuno You can check in description box only for individual videos

  • @anamikachaudhary6814
    @anamikachaudhary6814 ปีที่แล้ว

    Order_date column is in text format , maybe that is why it is giving me null select month(order_date) from superstore data table. Can you please suggest why is this happening. it pull null values for me. I am using MySQL workbench and when I use select EXTRACT(MONTH FROM Order_Date) as month from superstore_orders; it pulls null values for all the columns . Can someone help please.

  • @themightyvk
    @themightyvk ปีที่แล้ว

    Thanks buddy...

  • @prasadchowdary4870
    @prasadchowdary4870 11 หลายเดือนก่อน

    Where we can download the superstore data

  • @riyalmasla
    @riyalmasla 9 หลายเดือนก่อน

    thank you

    • @ankitbansal6
      @ankitbansal6  9 หลายเดือนก่อน

      You're welcome

  • @harshupreti1526
    @harshupreti1526 ปีที่แล้ว

    Why use sql when we have powerful tools like powerbi , tableau ? I am very curious and no way mean to disrespect . Please answer

    • @aayushibirla2590
      @aayushibirla2590 ปีที่แล้ว +1

      SQL is used for storing and retreiving data from database. Power BI and tablaeu are the data visualization tools. Here we just load data and make visualizations from it.

    • @afonsoosorio2099
      @afonsoosorio2099 ปีที่แล้ว

      @Harsh, that is a valid and legitimate question. I had the very some concern but after doing some training in SQL, now I understand that it is a must skill to command in data analytics.
      You are absolutely right there are powerful data analysis tools such as power query, power BI, Python and R.
      We need SQL because is where we will often get plain raw data stored in multiple related tables (RDBMS).
      So we have to query and retrieve the subset or dataset we are interested in for detailed analysis using those powerful data analysis tools.
      Hardly you will get stored in spreadsheet and tabular format like Excel, or CSV and ready for analysis.
      In a nutshell, we need SQL for extracting datasets from database and then transform and get loaded in a powerful data analysis tool.

  • @mujeebalam7885
    @mujeebalam7885 หลายเดือนก่อน

    SELECT employee_id, first_name, salary,
    LAG(salary, 1) OVER (ORDER BY salary) AS previous_salary,
    LEAD(salary, 1) OVER (ORDER BY salary) AS next_salary
    FROM employees;

  • @jasleenkaur-cw2fw
    @jasleenkaur-cw2fw ปีที่แล้ว

    can you please provide the dataset?