Hi,
There's a lot to say about derived tables, just thought I'd mention this since it's the same thing but written in a different way:
With tbl1 As ( select regmonth ,count(studentid) as totalstud, count(coursename)as totalcourse from tbl_studentcoursereg group by regmonth)
select regmonth, totalstud, totalcourse
from tbl1
where tbl1.totalstud>2
Here tbl1 is called a "common table expression" , using this can make the query a lot more readable because of the separation of the derived table from the rest, so you'll be using tbl1 just like it were a temporary table
Also, it would be a good idea to use a more logical name in stead of tbl1, e.g. TotalsPerMonth, so the query will look more like plain English
commented on Apr 21 2012 3:32AM