SQL Group By: An Explanation and How To Use It
HTML-код
- Опубликовано: 22 май 2024
- The SQL GROUP BY keyword is a powerful feature that lets you summarise data from your query into groups.
This can be helpful to see the number of employees in a department, or the total value of sales per month, and much more. Any time you need "something PER something else", it's often done with an SQL Group By.
In this video, you'll learn what Group By is, a step-by-step process on how to write one, what happens if you don't include Group By, and some examples.
Timestamps:
00:00 Start
00:09 What is Group By?
00:30 Sample table
00:49 First query
01:34 Group By question
01:46 Start a Group By query
02:37 Add an Order By
03:04 Can we exclude Group By?
03:59 Using another aggregate function
/// RESOURCES
📝 Get my free SQL Cheat Sheets: www.databasestar.com/get-sql-...
🧭 SQL Roadmap from basics to advanced: www.databasestar.com/sql-road...
✍️ Learn how to design a database: databasestar.mykajabi.com/edd
📧 Contact me here: www.databasestar.com/contact/
📝 Database Design Exercises: bbrumm.gumroad.com/l/hqsxi
📝 SQL Practice Questions: bbrumm.gumroad.com/l/ulekqk
📝 SQL Performance Quick Guide: bbrumm.gumroad.com/l/fcvny
📝 Ultimate SQL How-To Guide: bbrumm.gumroad.com/l/oqggau - Наука
I don't usually comment on tutorial videos, but this video is so clear I just want you to know how helpful you are for beginners like me
Glad it was helpful!
you are definitely a database star. Thank you
Thanks!
Mate you clarified something for me, I was wondering why I always had to add every other column I had to group by :) plenty helpful keep up the great tutorials!😃
Glad it helped you understand the concept further!
thanks sooooo much dude
i NEVER wrapped my head around how this works
now i am crystal clear :)
Awesome, good to hear!
Your SQL video was exactly what I needed. Thank you for explaining it so clearly. 😄🎬💻🔍
Thanks, glad you liked it!
Thank you for explaining it in such a simple way :)
You're very welcome!
your explanations resonates with me on a deep level.
This makes me happy. I’m glad the explanations help you!
Very well explained. Aggregated function was helpful to me. Thank you
Glad it was helpful!
This was helpful and clear, thank you! I liked your group by question, because I tend to create a question like that when I'm struggling to formulate the correct query.
Glad it was helpful!
Thanks for actually explaining it.
You’re welcome!
I'm preparing for DP-900 exam and I was having a hard time with the Group By statement and aggregate functions. This video has helped me understand it perfectly. Thanks! Subscribed.
Thanks! I'm glad the video helped you understand it.
Super helpful. First slide's visual really helped...
Glad you liked it!
very detailed. clear. beautiful
thanks ALOT
really helpful
Glad it was helpful!
Thank you for this very useful video!
No problem, glad you liked it!
awesome most easiest explanation. Thanks man
Glad it helped!
very helpful; thank you!
Thanks!
real good video, thank you!
You’re welcome!
that waaaaas veeeeery helpful thaaaaaank you
You're welcome!
👋 Bravo!
A very well-explained demo!
Thanks!
@@DatabaseStar....... You're very welcome!
Can you please make a crash course about "MySQL for Advanced Data Analytics"?
Excellent video !
Glad you liked it!
Cheers boss, I knew I had to use Group By but I didn't fully understand why.
Thanks, glad it was helpful!
thanks it really helped
Glad it helped!
Nice video! Your indentation hurts me, but thank you for this video; It is very well presented!
Thanks! Do you prefer a different style of indentation for SQL code?
Thanks for that.
Glad it was helpful!
thank you.
You're welcome
Very good information
Thanks!
Thank you 👍
No worries!
Good to know, most important part was that the field selected should be in the group by clause. THey completely left that out in class
Glad you liked the video. Can’t believe they left that out of your class!
@@DatabaseStar It was a very rushed class tbh. Teaching finished at the beginning of November so I'm self-studying for finals😅😅
My only question is if you have 3 columns in the Select Statement with an aggregate function, for example, is it mandatory to always include all 3 columns in the group by clause? And if not, then how do we know which of the 3 columns must be included?
Good question. Yes, it's mandatory to include all three columns in the Group By clause. If you don't, you'll get an error about columns in the Select not in the Group By (the exact error will depend on the database vendor).
The only exception is some versions of MySQL allow you to have a mismatch between the Group By and the Select. But you'll get a result that won't be correct, such as showing the first group only but the aggregate function on all rows.
@@DatabaseStar Thanks for the awesome reply! I just subscribed.
Can you please give an example with two tables that have many to many relationships
Good idea, I can do that.
Thanks
No problem!
I honestly gonna die with this language :")
Hahah
🙌
Thanks!
Can you t sql vedios
Sure I can make TSQL videos.