gwt
gwt

Reputation: 2413

How to get maximum count of a field in a table in Tsql and groupby

I have a table Customer_Complex_LoginLogs to log customer entrance.

I want to get the maximum number of entrances that has occurred on a single day (and I want to know the day that this occurred).

I know I should perform a group by TFEnteranceDate

How can I achieve this in TSQL ?

TableName :

Customer_Complex_LoginLogs

Table fields :

Id guid  PK
Id_Customer guid   FK
TFEnteranceDate datetime
TFEnteranceDatep nvarchar(10)

Upvotes: 0

Views: 113

Answers (1)

Steve
Steve

Reputation: 216293

Without more information this could be a simple GROUP BY

SELECT TOP 1 TFEnteranceDate, Count(TFEnteranceDate) as Enterance
FROM Customer_Complex_LoginLogs 
GROUP BY TFEnteranceDate
ORDER BY Count(TFEnteranceDate) DESC

EDIT: The day with the max number of TFEnteranceDate recorded

Upvotes: 3

Related Questions