Student (*sid: integer, *sname: string, *age: integer)
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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 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
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
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.