Reputation: 27
I have set of data Name, Id and Joined Date ,want to Group by Year 2019 before joined members and after joined members, need those counts. I tried below,
Select Year(JoinedDate),Count(1) from UserDetails
Group by Year(JoinedDate);
It's listed all the year, Please help me to get the solution.
Actual Data:
Expected Output:
Upvotes: 0
Views: 47
Reputation: 24793
Looks to me you want a conditional sum
SELECT CASE WHEN JoinedDate < '20190101' THEN '2019 before' else '2019 after' END AS [Date],
count(*) AS [Count]
FROM UserDetails
GROUP BY CASE WHEN JoinedDate < '20190101' THEN '2019 before' else '2019 after' END
Upvotes: 1