I have a below table
ID USER LOG_TIME REASON
1 PK 2018-07-11 11:00:00 R1, R2
2 PK 2018-07-11 10:00:00 R1
3 AK 2018-07-11 11:00:00 R2
4 PK 2018-07-11 11:30:00 R2
5 AK 2018-07-11 10:00:00 R1
6 PK 2018-07-10 10:00:00 R1, R2
7 AK 2018-07-11 09:00:00 R1, R2
8 AK 2018-07-11 07:00:00 R1
9 PK 2018-07-10 11:00:00 R2
10 AK 2018-07-10 11:00:00 R1, R2
I need the result with the details of the Last Log Time, and the Last Reason and the number of Logs on 2018-07-11. The Query i used is
select USER, max(LOG_TIME) as LAST_LOG, max(REASON) as REASON, case when date_format(LOG_TIME,'%Y-%m-%d')='2018-07-11' then count(*) end as CtLog from LogHistory group by USER order by USER;
The Result i get is being wrong. I need the result as below
USER LAST_LOG REASON CtLog
PK 2018-07-11 11:30:00 R2 3
AK 2018-07-11 11:00:00 R2 4
What changes are required
You can find the Table and query at http://sqlfiddle.com/#!9/c97574/3