Build an SQL query to answer the following questions:
What is the number of students tutored by each tutor? If the tutor has not tutored any student, your result should show 0 as the number of students tutored.
The SQL query for the above mentioned task would somewhat look like:
Select TutorName , count(distinct(studentID)) from TableName group by TutorName;
Here, we are select Teacher name to display and displaying the count of students by (student ID) that the particular teacher has tutored by using group by clause with Teacher Name with groups the data based upon the attribute ( here Teacher Name ) and then runs the select query.
Now, each teacher can teach same student in multiple subject, so to avoid data inconsistency, we have used distinct keyword as well. Has the table information been given, the query would have been far more accurate.
Get Answers For Free
Most questions answered within 1 hours.