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
Migrating to SQL Server 2005 from SQL Server 2000 is a hefty feat when compared to upgrading from 7.0 to SQL Server 2000. Site expert Adam Machanic ... Continue Reading
Multiple readers can sometimes read the same row simultaneously causing a false result. SQL Server 2005 expert Adam Machanic suggests modifying the ... Continue Reading
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
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.