Friday, March 9, 2012

help with query

i have 2 tables
table1: ClassBase
table2: ScheduleBase

ClassBase (ClassId(guid), ClassName(nvchar))
ScheduleBase (ScheduleId(guid), ClassId(guid from classbase), Date (datetime))

what i want to do is get the top 10 classes scheduled
right now i have
SELECT ClassBase.ClassName FROM ClassBase INNER JOIN ScheduleBase ON ClassBase.ClassId = ScheduleBase.ClassId

this returns all, how do i add something like a distinct count()

thanksTry:


SELECT TOP 10 ClassBase.ClassName FROM ClassBase INNER JOIN ScheduleBase ON ClassBase.ClassId = ScheduleBase.ClassId
|||ScheduleBase rows:
guid, guid.from.class, xx/xx/xxxx
guid, guid.from.class, xx/xx/xxxx
guid, guid.from.class2, xx/xx/xxxx

what i want is to get class name from ClassBase then count how many times that class has been sheduled. so something that'll return

guid.from.class = class 1 -> scheduled 2 times
guid.from.class2 = class2 -> scheduled 1 time|||Sounds like a GROUP BY

No comments:

Post a Comment