waseem
waseem

Reputation: 21

SQL Server: date function in group by clause

I have one table patient and column datetime

I want datewise count of patient table eg

1-1-2017  --- 10
2-1-2017 ----10

I am using below query but it also take time and output is like this

2017-02-02 11:41:13.497 --1
2017-02-02 11:36:16.823 --1
2017-02-02 10:27:47.027 --1

Upvotes: 2

Views: 35

Answers (2)

Abdul Rasheed
Abdul Rasheed

Reputation: 6709

Try this,

SELECT  CAST([datetime] AS DATE) [datetime],
        COUNT(*) AS [Result]
FROM    [patient]
GROUP BY CAST([datetime] AS DATE)

Upvotes: 2

Chanukya
Chanukya

Reputation: 5883

SELECT  CAST([datetime] AS DATE) [datetime],
        COUNT(*) AS [count]
FROM    [patient]
GROUP BY CAST([datetime] AS DATE)

Upvotes: 1

Related Questions