The provost wants to see the number of students in each major. Write a MySQL statement to display this.
Question
The provost wants to see the number of students in each major. Write a MySQL statement to display this.
Solution
Sure, here is a MySQL statement that could be used to display the number of students in each major, assuming you have a table named 'students' and the majors are stored in a column named 'major':
SELECT major, COUNT(*) as number_of_students
FROM students
GROUP BY major;
Here is a step by step breakdown of the statement:
-
SELECT major, COUNT(*) as number_of_students: This part of the statement is selecting the 'major' column and the count of rows for each major. TheCOUNT(*)function counts the number of rows. Theas number_of_studentspart is just renaming the column for the count to 'number_of_students' for the output. -
FROM students: This part of the statement is specifying the table to select from, which in this case is the 'students' table. -
GROUP BY major;: This part of the statement is grouping the selected rows by the 'major' column. This means that for each unique value in the 'major' column, it will count the number of rows and display it in the 'number_of_students' column.
Similar Questions
Write a query to display the student qualification(squal) and the total number of students based on their qualifications. Give an alias name as ‘totalStud’. Display only the squal having the totalStud count less than 8. Display the records sorted in ascending order based on squal.
Dr Stephane Nwolley wants to identify the students with a score greater than the average. Write a MySQL statement to identify these students. Display the student names (Join first name and last name and call it full_name), the score of the student, and their major.
A parent wants to determine the number of majors Ashesi offers students. As the database administrator, you are supposed to write a MySQL query to retrieve the number of majors Ashesi offers using the tables provided.
The Mastercard Foundation wants to find the majors are being paid an allowance greater than 7000. Write a MySQL statement to show this.
Give the database schema the following tables: Student (studentId, firstName, lastName, gender, birthday, phone, address, classId) Class (classId, className) Which code snippet will display records with the following 3 columns: classId, className and amount (amount of students)?SELECT c.classId, c.className, COUNT(*) AS amountFROM dbo.Class c INNER JOIN dbo.Student s ON c.classId = s.classId;SELECT c.classId, c.className, COUNT(*) AS amountFROM dbo.Class c INNER JOIN dbo.Student s WHERE c.classId = s.classIdGROUP BY c.classId, c.className;SELECT c.classId, c.className, COUNT(*) AS amountFROM dbo.Class c INNER JOIN dbo.Student s ON c.classId = s.classIdGROUP BY c.classId;SELECT c.classId, c.className, COUNT(*) AS amountFROM dbo.Class c INNER JOIN dbo.Student s ON c.classId = s.classIdGROUP BY c.classId, c.className;
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.