get a count of id for each month

arkiboys 9,701 Reputation points
2023-07-28T15:00:52.52+00:00

hello,

I have a table which has daily datetimestamp and loginID

I would like to get a count of the LoginID for each month. How can I do this please?

Timestamp LoginId


2020-12-11T15:01:54.201000+00:00 B22

2020-12-11T15:32:36.403000+00:00 A5

...

Thank you

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,423 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 116.4K Reputation points MVP
    2023-07-28T19:56:30.09+00:00
    SELECT convert(char(6), Timestamp, 112), LoginID, COUNT(*)
    FROM  tbl
    GROUP BY convert(char(6), Timestamp, 112), LoginID
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.