Using group by on multiple columns

0 votes
I recognize the purpose of GROUP BY x.

However, how do GROUP BY X, Y operate and what does it signify?
Sep 2, 2022 in Data Science by Kithuzzz
• 38,000 points
759 views

1 answer to this question.

0 votes

Group By X means to put all those with the same value for X in one group.

Group By X, Y means to put all those with the same values for both X and Y in one group.

Let's use the following table, which pertains to which university students are enrolled in which subjects, as an illustration:

Table: Subject_Selection

+---------+----------+----------+
| Subject | Semester | Attendee |
+---------+----------+----------+
| ITB001  |        1 | John     |
| ITB001  |        1 | Bob      |
| ITB001  |        1 | Mickey   |
| ITB001  |        2 | Jenny    |
| ITB001  |        2 | James    |
| MKB114  |        1 | John     |
| MKB114  |        1 | Erica    |
+---------+----------+----------+

When you use a group by on the subject column only; say:

select Subject, Count(*)
from Subject_Selection
group by Subject

Output:

+---------+-------+
| Subject | Count |
+---------+-------+
| ITB001  |     5 |
| MKB114  |     2 |
+---------+-------+

Unlock the power of data and embark on a journey towards becoming a skilled data scientist. Join our comprehensive Data Science Training program today!

answered Sep 3, 2022 by narikkadan
• 63,600 points

Related Questions In Data Science

0 votes
1 answer

Add two lines on graph using abline in R

I am using "y 0+x" to fit ...READ MORE

answered Jun 24, 2022 in Data Science by Sohail
• 3,040 points
607 views
0 votes
1 answer

Filter multiple values on a string column in dplyr

The filter() function is used to select ...READ MORE

answered Jun 14, 2022 in Data Science by Sohail
• 3,040 points
1,059 views
0 votes
1 answer

Converting xlsx to xls using Microsoft Office Compitablity Pack's excelcnv

Simply rearranging the positions of the parameters ...READ MORE

answered Mar 25, 2022 in Data Science by gaurav
• 23,260 points
1,315 views
0 votes
0 answers

Determine the data types of a data frame's columns

I'm using R and have loaded data ...READ MORE

Jun 1, 2022 in Data Science by avinash
• 1,840 points
405 views
0 votes
1 answer

Reasons for using the set.seed function

The requirement is a desire for repeatable ...READ MORE

answered Jun 20, 2022 in Data Science by Sohail
• 3,040 points
414 views
0 votes
1 answer

plotting in different shapes using pch= argument

plot(Sepal.Length ~ Petal.Length, ...READ MORE

answered Jun 23, 2022 in Data Science by Sohail
• 3,040 points
489 views
0 votes
1 answer

Using ORDER BY and GROUP BY together

Correctly use the  group by: select l.* from table ...READ MORE

answered Sep 20, 2022 in Database by narikkadan
• 63,600 points
741 views
0 votes
1 answer

How to use count and group by at the same select statement

This will do what you want (list of ...READ MORE

answered Nov 7, 2022 in Others by gaurav
• 23,260 points
888 views
0 votes
1 answer

Which query to use for better performance, join in SQL or using Dataset API?

DataFrames and SparkSQL performed almost about the ...READ MORE

answered Apr 19, 2018 in Apache Spark by kurt_cobain
• 9,350 points
1,855 views
0 votes
1 answer

How to connect Java program to the MySQL database?

You can connect your Java code with ...READ MORE

answered May 11, 2018 in Java by Parth
• 4,640 points
1,929 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP