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
Database servers needed for a site with thousands of users can vary depending on a number of factors, including your necessary level of load ...continue reading
Database Snapshots feature in SQL Server 2005 Enterprise Edition creates read-only files. For these separate databases, our 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.