Home > database >  And the amount of codes to the number of times a day at most
And the amount of codes to the number of times a day at most

Time:10-02

Date name sign in
Zhang y 2016-01-01
Zhang y 2016-02-02
Zhang y 2016-01-02
Zhang y 2016-01-02
Zhang y 2016-01-02
Zhang y 2016-01-03
Zhang y 2016-01-04
Zhang y 2016-01-04
Zhang y 2016-01-04
Zhang y 2016-01-04
Zhang y 2016-01-04
The 2016-02-02 li bai y
The 2016-01-03 li bai y
The 2016-01-03 li bai y
And the 2016-01 month window to a few times is most times?
Results in January zhang signed in the most is five times a day, li bai 2 times

CodePudding user response:

 select name, count (*) number 
The from t
Where..
Group by name
The order by 2 desc

CodePudding user response:

reference 1st floor wmxcn2000 response:
 select name, count (*) number 
The from t
Where..
Group by name
The order by 2 desc

The back of the GROUP BY plus date field

CodePudding user response:

refer to the second floor sych888 response:
Quote: refer to 1st floor wmxcn2000 response:

 select name, count (*) number 
The from t
Where..
Group by name
The order by 2 desc

GROUP BY behind plus date field

The forehead may I express is wrong, so
If there are 5 times in January 1, 2 have 6 times, there are 7 4 times,,,,,,, find out the biggest, rather than seek out of a total of how many times in February?

CodePudding user response:

reference u011809117 reply: 3/f
Quote: refer to the second floor sych888 response:

Quote: refer to 1st floor wmxcn2000 response:

 select name, count (*) number 
The from t
Where..
Group by name
The order by 2 desc

GROUP BY behind plus date field

The forehead may I express is wrong, so
If there are 5 times in January 1, 2 have 6 times, there are 7 4 times,,,,,,, find out the biggest, rather than seek out of a total of how many times in February?


Well, just reference tip # 2 is ok;

CodePudding user response:

With tt as (
Select the name, date, count (*) CNT
The from t
Where..
Group by name, date)
Select the name, date, Max (CNT) from tt group by name, the date;

CodePudding user response:

Select the name, number of count (*)
The from t
Where 1=1
Group by name
  • Related