Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MSSQL active users by month

I would like to know the number of active users by month, I use MSSQL 2017.

I have an AuditLog table like:

- UserID: int
- DateTime: datetime
- AuditType: int

UserID  DateTime     AuditType
------------------------------
1       2022-01-01   1
1       2022-01-15   4
1       2022-02-20   3
2       2022-01-10   8
2       2022-03-10   1
3       2022-03-20   1

If someone has at least one entry in a given month then he/she is treated as active.
I would like to have a result like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Date     Count
2022-01  2
2022-02  1
2022-03  2

>Solution :

I think you can combine the function Month(datetime) in the GROUP BY with the Count function SELECT COUNT(UserID)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading