Intermediate SQL Tutorial | Partition By

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Take my Full MySQL Course Here: bit.ly/3tqOipr
    In today's Intermediate SQL lesson we walk through Using the Partition By. ____________________________________________
    SUBSCRIBE!
    Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content!
    ____________________________________________
    RESOURCES:
    Coursera Courses:
    Google Data Analyst Certification: coursera.pxf.i...
    Data Analysis with Python - coursera.pxf.i...
    IBM Data Analysis Specialization - coursera.pxf.i...
    Tableau Data Visualization - coursera.pxf.i...
    Udemy Courses:
    Python for Data Analysis and Visualization- bit.ly/3hhX4LX
    Statistics for Data Science - bit.ly/37jqDbq
    SQL for Data Analysts (SSMS) - bit.ly/3fkqEij
    Tableau A-Z - bit.ly/385lYvN
    Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!
    ____________________________________________
    SUPPORT MY CHANNEL - PATREON
    Patreon Page - / alextheanalyst
    Every dollar donated is put back into my channel to make my videos even better. Thank you all so much for your support!
    ____________________________________________
    Websites:
    GitHub: github.com/Ale...
    ____________________________________________
    All opinions or statements in this video are my own and do not reflect the opinion of the company I work for or have ever worked for

КОМЕНТАРІ • 202

  • @pana71
    @pana71 3 роки тому +225

    You know it's serious when the thumbnail has the suit

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +27

      😂😂

    • @Thedeepanshu95
      @Thedeepanshu95 3 роки тому +8

      Now I'm only looking for Suit in the thumbnail when I am in the mood of learning something 😅

    • @judugar
      @judugar 10 місяців тому

      Hahahahahahaha

  • @AkporHari
    @AkporHari 2 роки тому +80

    Thank you, Alex. This is the best explanation of GROUP BY statement, for me: "The GROUP BY statement is going to reduce the number of rows in our output by actually rolling them up and then calculating the sums or averages for each group."
    You make things so easy to understand.

    • @saniagus1
      @saniagus1 Рік тому +1

      you rewords it into an easy to digest sentence

  • @mayankdewli1010
    @mayankdewli1010 2 роки тому +32

    Thank you so much Alex! Best tutorials on SQL by far. No wasting of time. Straight to the point. I learnt so much in just a couple of hours.

  • @AmanyEzzat
    @AmanyEzzat 3 роки тому +19

    The first time I hear of Partition Over was yesterday when I was going through portfolio project #1, I'm glad to find a tutorial by you that explains it, Thank you, Alex! Great content!

  • @scorpion7434
    @scorpion7434 Рік тому +4

    "We have to group by all of the selected columns" .... This is the first time I hear this life-saving statement ... I have been getting this error many times for months and could not discover this myself nor did I heard it ever from any tutuor!
    Congrats for the new subscriber = Me!

  • @edricnes5882
    @edricnes5882 2 роки тому +13

    At this point I'm just gonna spam your videos with comments anyway, but again excellent video Alex. Know in your heart that your videos help others like me who wanna switch career to the data field by a lot! Your videos have amazing content, well organized, concise and have saved me a lot of time compared to watching 3 hours long tutorials. May life treat you well as it should!

  • @AndrewMoMoney
    @AndrewMoMoney 3 роки тому +26

    Simple, clear, and excellent content as always!

  • @austin16377
    @austin16377 Рік тому +39

    Example:
    AVG(Salary) OVER (PARTITION BY CompanyDepartment)
    First, look at the "PARTITION BY CompanyDepartment." This means to find all the possible groups in that column, CompanyDepartment. So let's say that all the possible groups are Sales Department, Marketing Department, and Engineering Department.
    Now, take a look at the "AVG(Salary)." This means that for each group (which we found above), find the AVG(Salary) for that group. For this example, this means that for the Sales Department, find the AVG(Salary) for that department. And same for the Marketing Department and Engineering Department.
    This is my thought process for how to think of PARTITION BY, but everyone has their own thought process, so if your way works, then it works!
    I hope this helps!

    • @nyabudulu
      @nyabudulu Рік тому

      its probably more useable in some scenario than COUNT(Gender) OVER(PARTITION BY Gender). love your brief explanation of how using OVER(PARTITION BY COLUMN_NAME)

    • @ailoveu100
      @ailoveu100 10 місяців тому

      it helps my friend GBU

    • @cynthiaanike3715
      @cynthiaanike3715 9 місяців тому

      Thanks for this! Really helpful

    • @frocks9248
      @frocks9248 6 днів тому

      Tnks for ur cmnt ,it was very grateful

  • @1689JeffChavez
    @1689JeffChavez Рік тому +1

    On my journey through the boot camp...
    Understanding the GROUP BY statement is becoming more clear as it is compared to other statements. Thank you.

  • @abhinendrsharma8137
    @abhinendrsharma8137 3 роки тому +4

    This course should be included as the perfect practical Visualisation of SQL in SSMS
    Appreciable👏👏

  • @oseikwamejones9019
    @oseikwamejones9019 Рік тому +2

    Two years ago but still educative. Thank you, Alex.

  • @lucad6649
    @lucad6649 2 роки тому +4

    You're a great teacher. I would totally love a full SQL course from you one day. Going through the videos is very edifying. Thank you.

  • @awimbley1336
    @awimbley1336 Рік тому +1

    I stumbled across your videos and I must say that they are the best. I like the chunking. You have the voice (tone, volume, etc) that makes it comfortable to listen to. I finally got to topics that were hard for me to understand but you break it down so eloquently. Thanks you for what you have and are doing. I want to better develop my skills as a Data Analyst and you are assisting in that.

  • @lemontea000
    @lemontea000 3 роки тому +4

    OMG! This is a huge help! I no longer have to join same table twice! Thank you!! :))))

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +1

      You’re most welcome! Glad it was helpful 😁

  • @helmybinmadi5776
    @helmybinmadi5776 Рік тому

    جزى الله الشدائد كل خير *** وان كانت تغصصني بريقي
    وما شكري لها حمدا ولكن *** عرفت بها عدوي من صديقي
    just would like to thank you, the way i thank great guys like you in my language "Arabic". i have done the beginners tut and just completed the intermediate. it cannot be easier than the way you have explained it. once thanks a ton and wish you the best of luck

  • @iraklisalia1533
    @iraklisalia1533 3 роки тому +3

    wow, super useful. I didn't know this and I would create temporary table and then join them by gender to get the output you mentioned here, but from now on I know Partition :) . Thank you so much!

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому

      That’s definitely a way to do it too!

    • @iraklisalia1533
      @iraklisalia1533 3 роки тому

      @@AlexTheAnalyst Wonder what next videos are? Maybe more window functions?

  • @12meeth34
    @12meeth34 Рік тому +1

    An even more useful analysis here can be done using AVG(Salary) instead of COUNT(Gender). This will give the average salaries of each gender which can be compared to each other and can also be compared to each individuals salary wrt their gender.

  • @samyaknagrale9566
    @samyaknagrale9566 4 дні тому

    i cant express how easy this was to understand. Thank you Alex so much

  • @adityashenoy2573
    @adityashenoy2573 3 роки тому +3

    Short ,Crisp and Concise ! 🔥
    Always love watching your videos!!!!

  • @jonathannali7682
    @jonathannali7682 3 роки тому +5

    Hi, I am still in the initial stages of Data Analytics, but this was very easy to understand. Thank you Alex 🤠

  • @rnjesus9950
    @rnjesus9950 10 місяців тому

    Thanks for the course, Alex. I'm working through for the first time having no prior experience. Playing around I calculated the average pay by gender and how far each employee is from the average using partition by and am completely amazed. This is really cool! You've done a great job laying it out.

  • @MrRubyElf
    @MrRubyElf 8 місяців тому

    Thank you so much for showing what the difference is. I'm working on a project using ChatGPT, and it used a partition by line. I had no idea what it was but you cleared it up!

  • @eliz964
    @eliz964 3 роки тому +3

    Aaawwww yes! Last night I literally started learning SQL. I picked a couple Udemy courses from the ones you previously recommended and bought them for cheap on Cyber Monday.
    Thanks for all you do!

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому

      That's great! Their $10 sale was nice! I picked some up myself haha

  • @harrisliao2509
    @harrisliao2509 3 роки тому +2

    clear demonstration with beautiful voice

  • @davestorm6718
    @davestorm6718 2 роки тому

    I used to use (pre SQL 2005) UDFs to do this inline (in the olden days). Wish I was paying attention when this feature was added - it would have saved a lot of time! Thanks for this great explanation!

  • @medimed-su3ir
    @medimed-su3ir 5 місяців тому

    I must Say Alex your Course is awsome , i just Started from Scratch , it is really really good

  • @hta-bi249
    @hta-bi249 2 роки тому +1

    Well explained. Thanks Alex! You hit the nail right on the head by explaining the 2 examples in the video.

  • @kaikai5356
    @kaikai5356 2 роки тому

    you are an amazing teacher.Couldnt believe how much i have learnt from you over these courses.im binging on your sql tutorials

  • @viktoriaballa4622
    @viktoriaballa4622 11 місяців тому

    DAY 3 of taking this course, and I finished Intermediate level SQL, thank you

  • @jacobmark8810
    @jacobmark8810 3 роки тому +1

    Parton By and Window Functions has got to be the coolest thing I learned in SQL thus far. No joke

  • @andieru6760
    @andieru6760 2 місяці тому

    this might be the best SQL video I have ever watched

  • @zidanhussain8092
    @zidanhussain8092 2 роки тому +1

    Good job alex, Just completed your basics and intermediate playlist. I have SQL as a chapter in middle school.

    • @Oluwagbeoyemiga
      @Oluwagbeoyemiga 2 роки тому +1

      I think we are almost on the same pace. Do you not mind if we could be buddy. We could share knowledge and drag each other sometime. I am just a first time learner and I am determined to become a Data Analyst.

  • @gulhermepereira249
    @gulhermepereira249 7 місяців тому

    simple example, perfect demonstration. Thank you, Alex!

  • @abdallahdikko8137
    @abdallahdikko8137 11 місяців тому

    now that's why he's the goat the goat.

  • @prithvipradip8467
    @prithvipradip8467 3 роки тому +2

    Alex! Really looking forward to the advanced tutorials!! Thanks much ! 🙂

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +2

      I have a few advanced ones out! More coming out soon!

  • @patrickmc8779
    @patrickmc8779 2 роки тому +1

    Amazing explanation and to the point. I will look into your other tutorials. Just needed this in combination with row number to solve a problem.

  • @lisaamante5384
    @lisaamante5384 3 роки тому

    Las Vegas, Nevada, USA: Wow! This is so cool. Thanks making it clear!

  • @cinemacolors
    @cinemacolors Рік тому +1

    Hey Alex, I love it! Glad to see that you used The Office (TV Series) cast names ;)

  • @nankundabridget9783
    @nankundabridget9783 9 місяців тому

    Thank you Alex . for the first time i have understood the use of partition by

  • @itsReshad
    @itsReshad 2 роки тому +2

    Very useful and you explain really well, thank you as always!

  • @sebulva
    @sebulva 9 місяців тому

    Loved The Office data.

  • @kstevens0915
    @kstevens0915 3 роки тому +1

    Simplest explanation ever!!

  • @DataScience111
    @DataScience111 2 роки тому +1

    short, précised, and excellent explanation.

  • @jonathanbrotto7278
    @jonathanbrotto7278 2 роки тому

    Being an old dog a bit seeing partition by would have been a life saver when using many group by and unionid and joined tables.

  • @riteshpillai4865
    @riteshpillai4865 2 роки тому +1

    Thank you soo much for making queries understanding in easier way. Keep posting more stuffs like this to help & motivate us in every step of building queries.

  • @sonabhatia4295
    @sonabhatia4295 3 роки тому +2

    Another great video Alex :)
    I have recently completed learning path of SQL for Data Science in LinkedIn Learning.
    What would you suggest i do next to further enhance my SQL skills?
    Also, thank you for connecting on LinkedIn

  • @djangoworldwide7925
    @djangoworldwide7925 7 місяців тому

    Basically the difference between summarise or mutate in R (or count/add_count)

  • @yoanperez172
    @yoanperez172 2 роки тому +1

    Excellent and very clear, thank you!

  • @nafsahmad5736
    @nafsahmad5736 2 роки тому +1

    Best tutorial ever!

  • @MethodOverRide
    @MethodOverRide 3 роки тому +1

    Would love to see more videos on Window Functions.

  • @seekerj1643
    @seekerj1643 2 роки тому

    Unless posted elsewhere might be a decent idea to show more about window functions and how you can even use it things like having rolling counter or much more IMO.

  • @adril.857
    @adril.857 2 роки тому +1

    Thanks so much! Way better than Data Camp! :)

  • @ChikamsoHope
    @ChikamsoHope 6 місяців тому

    Thanks for explaining so well

  • @MohammedAbdulQayyumKhan-c9q

    Whoa!! I had no idea you can do this with PARTITION BY, all this time I've been using subqueries to get this result.

  • @ManiSh-jl8ej
    @ManiSh-jl8ej Рік тому

    I Just Finish The Intermediate SQL Tutorial, And Now I Write Every Single Word With A Capital Letter Just Like SQL Query: D

  • @krishnabarfiwala5766
    @krishnabarfiwala5766 2 роки тому +2

    love the series

  • @ltcmdc1782
    @ltcmdc1782 Рік тому +1

    See, Partition by would have been REALLY great to know when I was trying to get a "total sum" of a given inventory item that was broken down by lots in a location. For example. Item 123 could have lot a, lot b and lot c in 1 location. there might be 2 in one lot, 3 in another and 5 in another. My solution was to subquery the "Sum all items in a location" then "Inner join" that sum and join on the Item Location (as that will always be unique)... so instead of having a really large query, this partition by would have shrunk the query down to an easy to read "Look here is the items, their locations and total sum of all the lots in each location..
    Well.. better late than never.

  • @wildgorilla1205
    @wildgorilla1205 Місяць тому +1

    Thx man!

  • @princechukwuemeka1947
    @princechukwuemeka1947 3 роки тому +1

    WHATS THE DIFFERENCE BETWEEN CHAR AND VARCHAR

  • @anthonynkem
    @anthonynkem 2 роки тому +1

    Thanks Alex, great tutorial.

  • @joshhayes3433
    @joshhayes3433 2 роки тому

    Had to watch this a few times to let it sink in, but great job, thanks for a simple example!

  • @user-cy4qx4yd9h
    @user-cy4qx4yd9h 2 місяці тому

    Hi Alex,
    When you explain the last query at the end, the one with aliasing to abbreviate the table names, in that query you use a Left Join. . What is the Left Join returning to us? Don't you mean Left outer join?

  • @noronhasanjay
    @noronhasanjay 2 роки тому +1

    Well presented and useful. Thank you Alex.

  • @alirezaghanbarzadeh1679
    @alirezaghanbarzadeh1679 3 роки тому +1

    it was a great way to compare partition by and group by. tnx

  • @MPN016
    @MPN016 2 роки тому +1

    you are awesome, keep doing videos please!

  • @rheamercadal6534
    @rheamercadal6534 3 роки тому +1

    This is super helpful Alex! Thanks a lot!

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому

      You’re very welcome! Glad it was helpful 👍

  • @Michael20
    @Michael20 2 роки тому

    this one is great. it's very similar to a fixed calculation from tableau

  • @pramodduvvuri7045
    @pramodduvvuri7045 3 роки тому +6

    Nobody's gonna talk about "The Office"? Toby is making 50000 No God No No NOOOOOOOOOOO

  • @billumbaggins3288
    @billumbaggins3288 Рік тому +1

    oh man this is a very good explanation

  • @raulmartellenriquez3712
    @raulmartellenriquez3712 Рік тому

    Great lessons, thx Alex

  • @saljeshmaharjan6760
    @saljeshmaharjan6760 Рік тому

    Cant stop thanking you alex

  • @Domi-49ers
    @Domi-49ers 3 роки тому +1

    Oh thanks men👍. Nice explained with comparison to group by🙂

  • @mahmoudferhat8031
    @mahmoudferhat8031 Рік тому

    Simple and clear. Thank you !

  • @krishnabarfiwala5766
    @krishnabarfiwala5766 2 роки тому +2

    thanks for this.

  • @BharatiyaFirstThanHinduMuslim
    @BharatiyaFirstThanHinduMuslim 9 місяців тому

    Good explanation .... thanks!

  • @kelthekonqrr
    @kelthekonqrr Рік тому

    This makes sense, so partition by just allows us see everything spread out, instead of the GROUP By.
    Question, will we still need to use "HAVING" Instead of "WHERE" ?
    I'm just asking this to help other viewers curiosity lol

  • @deepikagoyal07
    @deepikagoyal07 Рік тому

    Thanks for such a well explained content. I was able to visualize and understand clearly.

  • @kunlemaxwell
    @kunlemaxwell 2 роки тому

    Your contents have given me direction in my journey to being a Data Analyst. Thank you Alex. I was thinking, what's the difference between the PARTITION and ORDER BY?
    would it be possible to achieve the same result using an ORDER BY Gender ASC, function after the "ON" clause?

  • @davehan241
    @davehan241 2 роки тому

    So is the "dbo" not needed in general when referring to the tables? Dipping my toes in SQL and these videos are really helpful, much appreciated.

  • @shafickrahman88
    @shafickrahman88 3 роки тому +3

    Hey Alex I'm currently working as SQL Dev for US healthcare insurer. I basically write complex SQL queries as per given Requests and pull data and send it ...
    I'm just curious what I have to do next in order to enhance my career.. I hope you read this comment.. Waiting for your response.

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +4

      I would probably look at Temp Tables, Stored Procedures, and automating tasks in SQL. That would definitely enhance your career. Good luck!

  • @romanvasiura6705
    @romanvasiura6705 2 роки тому +1

    Thank you!

    • @romanvasiura6705
      @romanvasiura6705 2 роки тому

      I watched this video one more time...
      For me OVER (PARTITION BY) was a new statement - therefore I searched for a little bit more information about it...
      I need to admit it's a good tool to manipulate data.
      P.S. For some reason when I watched this video first time I missed your explanation of "OVER" power. It was a good idea to rewatch video one more time 😀

  • @mubashiraqeel9332
    @mubashiraqeel9332 3 роки тому +1

    I am looking forward to the advanced videos

  • @maximillianquaife-larsen3799
    @maximillianquaife-larsen3799 6 місяців тому

    Great video thank you

  • @woltron4o
    @woltron4o 3 роки тому +1

    Great Video, Thanks :) !

  • @pramudyadika_
    @pramudyadika_ Рік тому

    Thanks, Alex!

  • @tyroneogarrojr.453
    @tyroneogarrojr.453 2 роки тому

    Great video, very comprehensive!

  • @Venky_Himalay
    @Venky_Himalay 2 роки тому

    Realy Thnk you sir for your service Loved it.

  • @untangledyogi4864
    @untangledyogi4864 Рік тому

    Thank you so much @Alex

  • @anthonyd9043
    @anthonyd9043 Рік тому

    Makes sense, thanks Alex!

  • @smokystar6701
    @smokystar6701 3 роки тому +1

    Can you please do a tutorial on self-join

  • @michaelsalgado-e5q
    @michaelsalgado-e5q Місяць тому

    You always remind me of the Tim Ferriss of SQL

  • @ayaqz3144
    @ayaqz3144 11 місяців тому

    thank you sir , i appreciate your hard work

  • @chrisomoha636
    @chrisomoha636 9 місяців тому

    awesome lessons

  • @tagoreji2143
    @tagoreji2143 2 роки тому

    Thank you, Sir. All Good to you

  • @moisesdiaz9852
    @moisesdiaz9852 3 роки тому +1

    Great tutorial as always

  • @sakirinteser9536
    @sakirinteser9536 3 роки тому +1

    Please make a video on how to create sql reports and visualization on Excel.

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому

      I will definitely be doing that in the future 👍

  • @dominiquepenn9477
    @dominiquepenn9477 7 місяців тому

    Thank you 😊

  • @CataldiGabriel
    @CataldiGabriel 2 роки тому

    Thanks! Help a lot!

  • @leprincessuu
    @leprincessuu Рік тому

    Hi Alex, thank you so much for your videos, you are a life saver. I was wondering: why don't you add the aliases to the beginning of the SELECT statement? (ie. dem.FirstName, dem.LastName, dem.Gender?) TIA! Or if anyone else could help me answer this question that would be great.

  • @kamaur01
    @kamaur01 Рік тому

    Lucky video 13 piqued my interest.