nested query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    nested query

    How should I do this...
    First I wanted to count the students who enrolled but I wanted also to count on the same query how many are new enrollees. I cannot add the New or Old condition at the bottom because I dont want my result to be resticted. So I added a select in between and put the condition just to count how many are New enrollees. I hope I explain this clearly.

    Code:
    SELECT [Sch ID],
           count ([Student ID]),
           [Enrolled Date],
           count ([Student ID]),
           count (select [New or Old] from rawdata where [new or old]='old')) as NEW
    FROM tblData
    GROUP BY 
           [Sch ID],
           count ([Student ID]),
           [Enrolled Date],
           count ([Student ID]),
           NEW
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    Code:
    SELECT [Sch ID], 
           count ([Student ID]), 
           [Enrolled Date], 
           count ([Student ID]), 
           count (CASE WHEN [new or old]='old' THEN 1 ELSE NULL END) as NEW 
    FROM tblData 
    GROUP BY  
    	[Sch ID], 
        [Enrolled Date]

    Comment

    Working...