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
Database Snapshots feature in SQL Server 2005 Enterprise Edition creates read-only files. For these separate databases, our 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
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
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.