Student (*sid: integer, *sname: string, *age: integer)
Class (*cname: string, *meets_at: datetime, *day: datetime, *room: string)
Enrolled (*sid: integer, *cname: string)
What query would you write to find the names of the students enrolled in the largest number of classes?
SELECT S.SName, COUNT(*) AS EnrolledCount FROM Student S JOIN Enrolled E ON S.sid = E.sid GROUP BY S.SName ORDER BY COUNT(*) DESC… But you'll have to decide what "largest number" means and add your own logic to filter the results further based on a threshold number that qualifies. You might employ a HAVING clause for that purpose.
Dig Deeper on SQL-Transact SQL (T-SQL)
Related Q&A from Adam Machanic
SQL Server 2005 and T-SQL do have differences. The advantages and disadvantages would depend user environment as described by SQL Server 2005 expert... Continue Reading
SQL Server expert Adam Machanic highlights the differences to consider when weighing the move to SQL Server 2005 Enterprise and Standard Edtions. Continue Reading
Writing a generic audit trail trigger in SQL Server to keep track of inserts, deletes, and updates within a table is explained in this expert ... Continue Reading