What is the output of the following query?
SELECT EnrollmentDate, COUNT(*) AS StudentCount
FROM Person
WHERE EnrollmentDate IS NOT NULL

 Posted by Kmandapalli on 1/22/2014 | Category: LINQ Interview questions | Views: 1344 | Points: 40
Answer:

In the below query, we have a table named Person containing EnrollmentDate and so on. This Enrollment column allows nulls while insertion. We are performing the select command based on EnrollmentDate column which is not null. ie, first it checks only for the rows that contain a value in the Enrollment column, then performs GroupBy.
Then it searches for the rows that contains the same EnrollmentDate, counts the number of rows and displays them in the StudentCount column.

Suppose if we have a table like below:

EnrollmentDate Name
01-01-2013 aaaaaaaa
01-05-2013 bbbbb
01-01-2013 ccccccc
01-01-2013 ddddd

Then the ouput will be
EnrollementDate StudentCount
01-01-2013 3
01-05-2013 1


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response