SQL Window Functions: Explained (with examples)

แชร์
ฝัง

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

  • @eminjs2319
    @eminjs2319 ปีที่แล้ว +11

    First of all, thanks for clarification. Second, just to warn some people like me who could potentially be stumped by a little typo: in 6:09, in the presentation, write to the order_id 5 the date also 2022--04-03, and not 2022-03-03, otherwise we would not have a logical grouping. Again, I want to than you again Ben: only after watching this video I truly feel that I grasp the window functions completely. Kudos to your amazing clarification skills.

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

      Great, thanks for the correction and advice!

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

    you have the best SQL playlist, Thank you

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

    Thanks, Ben! You nailed in the explanation and can show things in a very clear way.

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

    You have done great when it comes to good video creation and Knowledge delivery. Nice! Learned what I needed. Nice!

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

      Thanks! I’m glad you liked the video.

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

    Great teacher!!! One of the best I have seen.

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

    This is honestly such an amazing video. Thank you so much.

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

      Thanks! Glad you like the video.

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

    Another Awesome tutorial, crystal clear and concise by the SQL Master! This man is truly a legend! After numerous tutorial, I finally got my head arround the order by argument in the over ( ) clause. Thank you a lot. This is the relative sorting against or over the particular group/window.

    • @DatabaseStar
      @DatabaseStar  4 หลายเดือนก่อน +1

      Thanks! I'm glad it helped you understand.

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

    Clear & informative tutorial, thank you!

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

    Thank you so much for this. It was very clear and helpful.

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

    Thanks, this was helpful.

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

    very well explained

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

    YOU ARE THE BEST MATE!

  • @mohammadreza.beygifard
    @mohammadreza.beygifard 4 หลายเดือนก่อน

    Great Video!

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

    Great explanation. Thanks!

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

    This was very helpful! TY

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

    great video! very helpful! 😊

  • @张雪健-t2w
    @张雪健-t2w 2 ปีที่แล้ว

    Really helpful! Thanks!

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

    When adding the partition, I accidentally did not grab the "order by" for the outer query and it worked perfectly. So rather than add additional code to make it work, makes more sense to let it run with less code? Discovered this completely by accident. Here is the code.
    Select order_id,
    order_date,
    order_total,
    SUM(order_total) OVER (
    PARTITION BY order_date
    ORDER BY order_id ASC
    ) AS running_total
    From orders

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

      Thanks for the comment and the code. Yes, this query would run because you don't need that final Order By statement.
      Without that last Order By statement, the records are not shown in any specific order. The running total calculation for each row is still correct, but because the rows can be displayed in a different order, it may seem like the running total is jumping around or not in an order.
      Adding the Order By to the end will make the results look clearer or look like the running total is being shown in the right order. But, without it, the calculation is still correct as you have mentioned.

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

    Well presented!

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

    Are te windows function good for performance compared to other options retriving same results?

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

      Good question. It depends on the size of your table and several other factors, but I've found that they perform better than using a correlated subquery (which is an alternative way of getting the same data). You could test other approaches on your database and see if it is better or worse.

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

    Can we use where clause or any kind of filters in any way for each windows function seperately ?
    We are unable to fully utilize window function without where clauses... or any trick to do so in sql server ?

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

      Yes you should be able to use a window function and where clauses.
      The window function does the calculation and the where clause does the filtering.
      I don’t know if you can have separate where clauses for each window function. Perhaps surrounding it with a case statement?

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

      @@DatabaseStar can you please advise how to use where clause along with over clauses in windows function ?

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

    How to databases configuration?

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

      What do you mean?

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

    Could you not achieve the same results using a GROUP BY clause?

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

      Yeah you could achieve a similar result. However, window functions allow you to perform a calculation on one group of data and display the data in another group. A Group By will both display and calculate on the same group of data.

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

    I like the video and the channel content looks cool => subscribed

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

    Nice 👍

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

    BigQuery as well

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

    Hey man, glad to meet again.
    I have only a simple enquiry as a new sql learner.
    How order by clause differs from rank function in sql?
    Thanks for taking care of this.

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

      Good question. The Order By clause will sort the data in the order you specify. The Rank function will calculate where a row will fit in an order based on a criteria, but it doesn't change how the data is ordered.

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

      @@DatabaseStar
      I learned that rank () should be accompanied with over and order by clauses....So rank does dictate a change in the order of records? is that true?
      Here a sample of rank function in my query
      select id, rank() over(order by id asc)
      from val;
      Thanks

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

    💙

  • @БарзуПарпишоев
    @БарзуПарпишоев ปีที่แล้ว

    👍👍

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

    ♥️🙏🤝

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

    appreciate the video - but you're introducing concepts a little too quickly here - namely the frame -- the default frame - unbounded preceding to the current row - and this is a little too tricky for people to grasp without a direct explanation - the running total would make sense in light of the default frame.

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

      Thanks for the feedback! Window functions are a hard concept to understand and explain, so I appreicate the feedback on how I've explained it!

  • @Pranjal-AI
    @Pranjal-AI ปีที่แล้ว

    Very helpful, Thanks!