SQL Tutorial - Window Functions

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

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

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

    I loved this video, looking forward to see more videos from you

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

    I've seen so many videos trying to explain windows functions and none of them Explain it as you do. I think the difference is you showed the difference between using group by, CTEs and windows function. Thanks a lot, Dev.

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

    I came to TH-cam after going through a paid online SQL course wanting to understand window functions better. You explained/showed it to a level where conceptually it sunk in. Thanks.

  • @OldPick-Unix-dude-pb9jg
    @OldPick-Unix-dude-pb9jg ปีที่แล้ว +1

    I have watched this video, and others (in fact all of them), of yours and really enjoy your approach and pace. For what it's worth, I have watched many other SQL Tutorial channels, however, I find myself drawn back to your videos time and again.

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

    One of the best explaination of Window functions to get started on !!

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

    In the last bullet of your "Window Functions" slide, you want to use the preposition "into" rather than the phrase "in to". The result set is being split into partitions, denoting that the abstract positioning of the data is changing.

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

    A short time ago I was contacted by an employer for an SQL Developer job (Entry Level), and they wanted me to take a skills assessment. The manager told me that I should know CTE's and Window Functions. I was pretty comfortable with CTE's but I basically learned what Window Functions were (and how they are used) from your videos, and also found your CTE videos a useful refresher. I watched the series over a few times until I was comfortable playing around on my machine with them, and, turns out, like 90% of the assessment was a practical coding assessment for Window Functions/CTE's (moderately more complex than the examples in your videos). I ended up being hired for the position.
    I just wanted to say that I appreciated your videos and they were apparently clear enough to both introduce Window Functions and help me understand it enough to apply it appropriately (in tandem with playing around a bit with a practice database i.e. AdventureWorks). So thanks!

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

      That’s absolutely fantastic news, congratulations on the position. It’s great to hear you took the concepts from the videos and were able to apply it to different databases and answer questions, that’s exactly what I was hoping for when I set up the channel. Keep asking questions and learning and you will go far.

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

    Wow! I've literally been searching for an easy-to-understand explanation of what Window Functions are, and this one is the best explanation so far. Thank you so much!

  • @BillSmith-iw4wm
    @BillSmith-iw4wm 2 ปีที่แล้ว +1

    The best description of windows functions that I have seen. Thank you!

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

    You are by far the best SQL tutor. I dont get it why you dont have many subscribers and views. Great videos.

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

    Thank you so much, i was never able to understand these until now !

  • @Fat1Dada
    @Fat1Dada 5 ปีที่แล้ว +6

    Awesome introduction to Window functions. Clear as Icelandic water on a sunny day. good job

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

    Awesome video, thanks! The explanation is better than some paid online courses provide. It would be great if you also shared the table you use for querying to be able to practice and compare the results.

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

    Explain window functions with examples (sum, count) very clearly. Thank you.

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

    Short, convice and to the point. Very good video!

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

    Great video. one of those topics as a software dev I never really cared to look into but glad you made it so simple to learn!

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

    Love your SQL tutorial videos! Help me a lot. Super clear and easy to understand.

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

    Very well explained video. I studied it for the first time and clearly understood it. Thanks!

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

    Thanks a lot the best explanation for OVER() and PARTITION BY I ever seen :)

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

    Another great tutorial from BeardedDev!!

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

    Clear and logistic! I find a lot of videos about introducing window functions, but this is the best one and expound some relations between other functions!

  • @ALEX86ZILBER
    @ALEX86ZILBER 11 หลายเดือนก่อน +2

    great explanation of window functions, thanks a lot

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

    Your explaining methods and skills are awesome. It helped me a lot. Thanks.

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

    Very good demo and explanation for windows functions.

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

    great example, very well explained. Thank you.

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

    Awesome video! Love that you explained the group by version and included both in the description of the video. Thank you!

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

    Best explanation for Window functions! Can you please zoom in onto the area where you are writing the code, I listen to your videos on the go on my phone and it's not always easy to see what's being written on a mobile screen

    • @BeardedDevData
      @BeardedDevData  3 ปีที่แล้ว

      Thanks so much, appreciate the feedback, I have added zoom to my latest videos.

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

    Thank you for the video. Excellent tutorial and explanation.

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

    Cooool ! I was confused by the concept and now I fully understand!

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

    Great tutorial thank you!
    Done thanks took notes

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

    Very well explained. Thank you.

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

    thank you, thank you, thank you so much! you made this topic so easy to understand!!!

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

      Thanks so much for the feedback.

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

    Some videos on the Statistical functions would be fantastic.

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

      Hi, I will put them down on my to do list for the next couple of months.

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

    love the video! window function well-explained! Thank you so much! also love your accent!!!

  • @carsonneal3285
    @carsonneal3285 8 หลายเดือนก่อน +1

    Wonderful video. Is there a way to created window functions in “Views” - where you can see the tables and fields being used? All while still performing a window function

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

      You can create a window function in views but to see the table and columns being used you'd have to look at the definition of the view

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

    Dude, great video, well planned, well explained, good audio, amazing work.

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      Thanks, let me know if there are any any particular tutorials you would like to see.

    • @francescogalletta6215
      @francescogalletta6215 6 ปีที่แล้ว

      Absolutely mate. Maybe Git would be good hahahaha still a newbie

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

    yo I came here for window function but the axxxent is a def a bonus ;) love from the USA!

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

    I've always used the partition inside the over, so just using the over alone is pretty cool! A fellow developer I know uses the case statement. Very versatile, and much better than CTE's, IMHO.

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      That’s an interesting approach with CASE statements, what if you wanted partition by CustomerId and had 100s of customers or partition by multiple columns surely the approach would become way too long winded.

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

    Any plans to do a couple of videos on the Windows statistical functions?

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

      I can certainly do some, I'm just finishing off my DA-100 certification then I will be making a lot more videos

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

      @@BeardedDevData thanks, they would be great.

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

    Great video!
    If you could make some videos with Problems where we would be using these Analytical functions, that would help the people preparing for interviews.
    And would help in better understand the topic.

    • @BeardedDevData
      @BeardedDevData  3 ปีที่แล้ว

      Great idea, I will come up with some scenarios.

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

    Please do work along projects for data analysis or business intelligence from start to finish. It'd teach how to do basic projects from start to finish. And would help in updating skills as well

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

    Your tutorial is just so amazing!!

  • @TonnyPodiyan
    @TonnyPodiyan 5 หลายเดือนก่อน +1

    Could you please share the dataset to practice along. Thanks !!

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

    Good explanation...
    Thank you :)

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

    Hi, love the tutorials. Have you done anything on using windows functions within multiple join selects?

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      Hi, do you mean using window functions over multiple tables joined together?

    • @claremckenna6703
      @claremckenna6703 4 ปีที่แล้ว

      @@BeardedDevData yeah, i'm using these functions for the first time and need to join multiple tables and use the right table info in the partition for different columns. Eg count and partition from table b for one column and do the same from table c for another. Just wondering if you had covered this at all. I've tried a few tests but with different results. I'm doing this in Salesforce marketing Cloud so its not a full sql db environment, so that might be why. Its sql server 2005.

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

      By the way love your videos. I'm learning a lot!

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

      I haven’t done a video on different partitions and joining tables in the same query but I will get one up as soon as possible.

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

    I was looking for Window Function in R and I got this. Anyway it was a great learning experience . For sure I gonna use it in the future.

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

    Great Video! I like the way you teach...

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      Thanks so much, look out for new videos coming soon

  • @vigneshnagaraj7137
    @vigneshnagaraj7137 3 ปีที่แล้ว +3

    Need dataset for all your window functions video tutorials as you are using different dataset for different videos

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

    clearly understand! Thank you for uploading this tutorial

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

      Thank you for the positive feedback, let me know if there is anything you would like me to do a video tutorial on

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

    Thanks for sharing this amazing SQL tutorial!

    • @BeardedDevData
      @BeardedDevData  5 ปีที่แล้ว

      No problem, more tutorials coming soon.

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

    Very good explanation

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

    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 ?

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

      Unfortunately not, window functions will run over the entire set of data. There are a couple of options, one is to build separate window functions and then join the results using derived tables or CTEs, this has the problem with running over the same data multiple times, the other option is to get creative with case statements, could potentially flag rows for whether they should be included in calculations or not, this isn't that straightforward though depending on what you want to achieve.

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

    Thanks a lot for this tutorial. can i get the either Db backup or script? so that i can practice?

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

      Hi Phung, unfortunately I no longer have the script for it but because of that I have made another video where you can follow along: th-cam.com/video/lBcDSsgp0RU/w-d-xo.html

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

      @@BeardedDevData Thanks you very much sir. much appreciate for your contribution.

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

    For this line , SUM(Line_Total) OVER() AS Total
    what is the point of adding the over clause? Is this the same as doing the sum(line_total) and then adding group by at the end? Is over() allowing us to skip the group clause? And is partition by essentially equivalent to group by when doing aggregate functions?

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      OVER() is used to define the window, as it’s blank all rows are considered. It will return the same value as grouping but with window functions we can retain the detail rows. PARTITION BY is part of the OVER clause and further defines the window, this is different from grouping, with grouping we lose the detail rows, with window functions we retain the detail. It is important to understand that grouping is evaluated before window functions, which are usually part of the SELECT clause but can be used in ORDER BY too. You can use grouping and window functions in the same query. You can find more information on logical query processing here: m.th-cam.com/video/sBRfBU5jh18/w-d-xo.html

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

    Great job explaining this concept!

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

    Awesome content

  • @Virtualangello
    @Virtualangello 3 ปีที่แล้ว

    Thank you. Awesome video

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

    Hi, thanks for the educational video. I am interested in the performance details, did you address this in a followup video somewhere? Can't seem to find it.

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

      Hi, thanks for your comment, I haven’t uploaded any videos yet on performance of queries but will be doing some over the next couple of months.

    • @marc2377
      @marc2377 5 ปีที่แล้ว

      @@BeardedDevData Awesome.

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

    Which video do you look at frames? I can't find it

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

      m.th-cam.com/video/6S7z2wabJxk/w-d-xo.html

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

    Great Video, Thanks! How to we select multiple conditions on the OVER part. e.g, Order numbers got repeated every day and we had to partition over 'day' AND 'order number' to get to the order total. Is this possible?

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      Yes, definitely, as you mentioned in the comments you just need to partition by day, order number.

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

    Top stuff!

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

    Great video! Thank you.

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

    Can you make a video about GROUPING_ID

  • @로그-v2i
    @로그-v2i 4 ปีที่แล้ว +2

    Beautiful!!!!!!

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

    Brilliant tutorial, thank you.

  • @frenkyb.1332
    @frenkyb.1332 6 ปีที่แล้ว +1

    Great video, thanks a lot :) Perhaps you know how to use window function in where clause? Let's say, I have a query like this:
    select count(inve_key) over (partition by inve_key) as c_inve_key
    from JEREIN
    and I want only results where c_inve_key is greater than 10. How to write this in where condition?

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      Hi, thanks for the feedback, that is a great comment, I am actually uploading a video on this next week so I will let you know as soon as it's available. We have to be careful when working with Window Functions with a WHERE clause as the WHERE clause filters data before the function is applied so if the data is needed it cannot be part of the WHERE clause. To resolve this issue I would generally use a CTE and add the WHERE clause when selecting from the CTE, have you used CTEs before?

    • @frenkyb.1332
      @frenkyb.1332 6 ปีที่แล้ว

      Yes I did. Not a lot, but I did it. My windows function is part of a much larger query. I would like to use where inside window function. Like you make partitioning, but only on limited sets.

    • @frenkyb.1332
      @frenkyb.1332 6 ปีที่แล้ว

      I mean like part of subquery :)

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

    Hello. Can I get the Data as I wish to practice it simultaneously

    • @BeardedDevData
      @BeardedDevData  3 ปีที่แล้ว

      Hi, please have a look at this video, m.th-cam.com/video/lBcDSsgp0RU/w-d-xo.html, included in the description is the code to create the table.

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

    Hi Beardeddev, from where I can get this Sales Database ?
    Actually I want to do hands on along with your tutorials.
    Would be glad if you provide the link of the same :)

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      Hi, thanks for your comment, I no longer have the database but if you need a demo database to work with you can download AdventureWorks, I’m going to being uploading a video on how to download and restore soon.

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

      @@BeardedDevData Okay no issues.

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      I’m going to do my best to make sure everyone can follow along in future videos, whether that be using AdventureWorks or creating my own, if you let me know if you have any difficulty I will help you through the examples.

    • @yachnahasija8515
      @yachnahasija8515 4 ปีที่แล้ว

      @@BeardedDevData Yeah actually it should be like that only, so that everyone can follow with you and can do hands on simultaneously. So, for now am practicing it with the databases that I already have, so yeah thanks a lot for your quick revert !!

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

    Is it anyway possible to have a copy of the database that you used for the demo

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

      Hi, unfortunately I no longer have the database but as so many people have requested it I’m going to upload a new copy that people can follow along to. I will upload it this weekend.

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

      Thanks Dev.... But I managed with the AdventureWorks database

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

    Good video. Thanks. Can we use where clause on aggregate function (eg: select count(*) over(partition by department_id order by department_id)no_emp ,e.* from employees e where count(*) >3;

    • @BeardedDevData
      @BeardedDevData  4 ปีที่แล้ว

      Unfortunately you can’t within the WHERE clause as this is evaluated before the aggregations are applied. If you need to filter based on an aggregate function you have the option of HAVING COUNT(*) > 3 if using GROUP BY or use a CTE and then adding a WHERE clause when selecting from the CTE.

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

    first time of seeing it, can decide to sub at the first time!

  • @abhishes
    @abhishes 5 ปีที่แล้ว +6

    One feedback. next time when you record your videos try increasing the font size. I'm trying to watch this video on iPhone and its impossible to see the text on the screen. Why not increase the font size? you have 99% white space on the screen.

    • @caraziegel7652
      @caraziegel7652 4 ปีที่แล้ว

      for an oldie like me, even watching on a PC, I cant read anything.

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

    can you provide your the create query as well so e can follow you along? loving your videos

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      Hi, I will put this up as soon as I can. Thanks for the feedback on the videos, let me know if there is a particular area you would like to see a video on.

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

    Great Job. John Snow!

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

    Wow, thank you so much!

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

    great lectures.

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

    Can you share the link to the database info so we can connect as well.

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

      Unfortunately I don't have it, but if you take a look at this video, th-cam.com/video/lBcDSsgp0RU/w-d-xo.html, the description includes the code to follow along.

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

    Awesome video, thanks!

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

      Thanks for the positive feedback.

  • @jasminet.williams7003
    @jasminet.williams7003 4 ปีที่แล้ว +6

    Really hard to see your queries on mobile phone :(

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

      mobile phone? not much better on a laptop!

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

      Appreciate the feedback, I have enlarged the queries on my latest videos so hopefully this is an improvement. I am also looking in to some software that will allow zooming in to show everything more clearly on all devices.

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

    very nice.

  • @onemanenclave
    @onemanenclave 5 ปีที่แล้ว +10

    Love the accent.

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

    Hey BeardedDev, I wanted to know the difference between Aggregate Function and Windows Function, Since they perform the same somewhat

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

      That's a really good question and the answer is quite extensive. There is generally multiple ways we can achieve the same result working with SQL and if we put performance aside it really depends on what we are trying to achieve. If we are looking at applying aggregates to a whole data set or just one type of group then group by is more suitable, there is also the benefit of the having clause that we can apply if we want to see groups that meet a criteria. When working with window functions, they are part of the select statement so filtering based on criteria can be more difficult but if we want to return the underlying data, calculate running totals/averages, find next or previous value then they're are extremely useful. That being said we can also use both together, we can group our data using group by and find out the total of all groups by using a window function. Hopefully that helps clarify the difference and I will be doing some videos over the next couple of months focusing on performance and I will cover the differences between how group by and window functions are executed.

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

    What if you wanted get the Sales_Details_ID on the row with an aggregate value (say MAX(Line_Total) ) within a Sales_Id group? So I want to look at each Sales_Id group, and get the Sales_Details_Id on the row with the maximum line_total. I've been looking for a way to do this without a CTE but that might end up being the only way, CTE + RowNumber() partition by sales ID

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

      So what I want is something like
      SELECT Sales_Details_ID, MAX(Line_Total)
      FROM Sales_Details
      GROUP BY Sales_ID
      (This wouldn't work however because Sales_Details_ID would have to be in the GROUP BY clause

    • @BeardedDevData
      @BeardedDevData  5 ปีที่แล้ว

      Can you tell me the relationship between sale_id and sales_details_id? The reason I ask is that if one sale_id can have many sales_details_ids related then when you group by sale_id which of the sales_details_ids would need to be returned? As one value can only be returned then you need an aggregate function on sales_details_id. If it’s a one to one relationship then you can group by sales_details_id.

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

      @@BeardedDevData So in my case it's EmployeeID, EmployeeReviewScore, and ReviewDate. The relationship is one EmployeeID to many EmployeeReviewScore and ReviewDate. What I want is the most recent EmployeeReviewScore for each employeeID. So I would need to do something like this:
      SELECT EmployeeID, EmployeeReviewScore, MAX(ReviewDate)
      FROM table
      GROUP BY EmployeeID
      I only want to group by EmployeeID, but SQL Server syntax requires you to group by ALL non-aggregate fields. If I add EmployeeReviewScore to the GROUP BY clause, then I'll get multiple rows for each EmployeeID, which I don't want.
      I've solved this by creating a CTE ordered by Date with a rownumber() partition and joining to that, but I was just wondering if there is a cleaner way I can do this without a CTE.

    • @BeardedDevData
      @BeardedDevData  5 ปีที่แล้ว

      In the scenario you have explained a CTE is the perfect choice, to get the result you require you need to perform multiple operations on the data, first identify the MAX(review date) and then use that to identify the employee review score. Of course there are other ways to do it using other types of temporary objects but I like to use CTEs for this exact situation. In fact when somebody asks me what a CTE is and what’s it’s used for I would describe this exact problem.

    • @DoctorDoomsPvP
      @DoctorDoomsPvP 5 ปีที่แล้ว

      @@BeardedDevData Okay, thanks for the advice and informational video

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

    very useful video but its hard to see the queries you wrote or the results on SQL can you zoom out them I literally can not see anything

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

      Thanks for the feedback, I will make sure I do this on new videos.

    • @1stname365
      @1stname365 5 ปีที่แล้ว

      @@BeardedDevData You are very welcome

  • @gt9538
    @gt9538 6 ปีที่แล้ว

    BeardedDev thank you, fair play.

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      Thanks, let me know if there are any any particular tutorials you would like to see.

    • @gt9538
      @gt9538 6 ปีที่แล้ว

      Conditional window functions come to mind, like max(case when)over(...). as opposed to case when max()over(). They are very particular for sure. but its not something that I find well explained in many literature. But mostly the former is of interest.

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

    very well explained

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      Thanks for the positive feedback.

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

    can we get the script for the database which is being used in video for explanation?

    • @BeardedDevData
      @BeardedDevData  5 ปีที่แล้ว

      I haven’t published the script anywhere, but I am going to make sure in my future videos that the scripts are available.

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

    ❤ Thank You

  • @matthewpacheco6071
    @matthewpacheco6071 3 ปีที่แล้ว

    How can we filter in these situations? I am trying to use a "WHERE" to only see Line_Count >= 3 but it's not working

    • @BeardedDevData
      @BeardedDevData  3 ปีที่แล้ว

      Because the window function happens in SELECT or ORDER BY phases you cannot filter in the WHERE clause in the same statement. To do this you need to use a derived table, SELECT * FROM ( ) AS D WHERE Line_Total >= 3

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

    not working over function in derby or sqlite getting error "
    [Exception, Error code 30,000, SQLState 42X01] Syntax error: Encountered "PARTITION" at line 2, column 22."
    SELECT SALES_ID,SALES_DATE,ITEM,PRICE,QUANTITY,LINE_TOTAL,
    SUM(LINE_TOTAL) OVER(PARTITION BY SALES_ID) AS SALES_TOTAL
    FROM SALES_DETAILS;

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

    Thank you! But please use some lower screen resolution. Not everyone is able to watch this in HD quality.😢

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

      Sure, thanks for the feedback.

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

    Is there a link to the data used?

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

      Hi, unfortunately I don't have the data but if you like to follow along, you can here: th-cam.com/video/lBcDSsgp0RU/w-d-xo.html

  • @AbhishekSharma-xe7gr
    @AbhishekSharma-xe7gr 2 ปีที่แล้ว +1

    i'll have to watch peaky blinders before watching this

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

    Can window function be applied to ORDER BY clause?

    • @BeardedDevData
      @BeardedDevData  6 ปีที่แล้ว

      You can add a Window Function to an Order By clause but I cannot think of a use case where it would be beneficial, did you just want to know if it’s possible or do you have a particular example you are working on?

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

    Paid 10k in tuition only to have to resort to youtube for an actual easy to understand lesson.

    • @BeardedDevData
      @BeardedDevData  3 ปีที่แล้ว

      I’m not sure what currency that’s in but I’m guessing it’s a lot, I see a lot of training providers are in it for the money and don’t deliver good content. It’s part of the reason I set up the channel, more people are needed in the world of data and analytics and training should be readily available. Microsoft offer a lot of free training through Microsoft Docs and Microsoft Learn and edX are also quite good.

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

    Sorry could anyone here help me out with the question about Window Functions, that: it's already include the ORDER BY, so is it necessary to explicit again when we back to the main query ORDER BY again.
    For example:
    SELECT sales_transaction_date, SUM(total_sales) OVER (ORDER BY sales_transaction_date) FROM sales ORDER BY sales_transaction_date;

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

      Yes, the order by within the windows function does not impact the order of the results even if it seems to do so. You must add an order by at the end of the query to guarantee ordered results.

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

      @@BeardedDevData Oh, thank you very much (Y)

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

    bearededlegend

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

    It is important to notice that the Sales_Date column in your DB has its value all truncated by days. So, if someone wants to do that with a more granular level of "datetime", this someone should learn how to truncate dates.

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

      I wouldn’t use the term truncate personally, the Sales_Date column is a data type of DATE which has a granularity of day therefore you are correct if you are using a DATETIME data type then you will need to remove the time element and for that I would recommend CAST or CONVERT. I generally only use the term truncate when removing characters from a string or removing all rows from a table but I’m aware other RDBMS might refer to the operation as truncate.

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

      @@BeardedDevData makes a lot sense. Thank you.

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

    here's the full window function playlist for anyone interested: th-cam.com/play/PLgR-BOYibnN0QqIPFbMlS01bw8x9g07Ll.html

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

    USEFUL