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.
Question
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.
Solution
Assuming that you are using SQL and your table name is 'students', the query would look like this:
SELECT squal, COUNT(*) AS totalStud
FROM students
GROUP BY squal
HAVING COUNT(*) < 8
ORDER BY squal ASC;
Here's the step by step explanation:
-
SELECT squal, COUNT(*) AS totalStud: This line is selecting the student qualification (squal) and the total number of students with that qualification. TheCOUNT(*)function counts the number of rows that match a specified criteria. TheASkeyword is used to rename a column or table with an alias. -
FROM students: This line is specifying the table we are selecting the data from, which in this case is 'students'. -
GROUP BY squal: This line is grouping the selected data by the student qualification, so we can get a count of students for each qualification. -
HAVING COUNT(*) < 8: This line is a filter that only includes groups that have a count of less than 8. -
ORDER BY squal ASC: This line is ordering the results in ascending order by the student qualification.
Similar Questions
Write queries for the following.Student_Result (Roll_No, Enrollment_No , Name, Div, Branch, Mentor , DBMS , DS ,JAVA_II , MATHS_II , FEE)(1) Display branchwise count of student in descending order.(2) Display the roll no, name and mentor of student who got less than 9 marks in anysubject.(3) Display the branchwise maximum total marks of all subject
Write a query to display the coursename of the courses having the coursefees above average fees of all the courses. Display the records sorted in ascending order based on coursename.Note:1. Display only the coursename of the courses having the coursefees above average fees of all the courses.2. Order by is mandatory.Sample Output:
Write a query to display all student details whose sname starts with ‘s’(case sensitive) and is of length between 5 and 20 and squal as ‘undergraduate’(case sensitive). Display the records sorted in ascending order based on sid.
The provost wants to see the number of students in each major. Write a MySQL statement to display 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.