表名:日志
id | userid | loginDate | type |
---------------------------------------------------------
1 | 1 | 2017-07-01 00:05:50 | 1 |
2 | 1 | 2017-07-01 06:06:50 | 2 |
3 | 2 | 2017-07-01 06:34:50 | 3 |
4 | 3 | 2017-07-01 06:56:76 | 1 |
5 | 2 | 2017-07-01 15:46:52 | 2 |
---------------------------------------------------------
我有一张这样的桌子。所以我需要每天过滤最后一次登录类型计数
我尝试了以下查询
SELECT
DATE(logindateindividual) AS loginlocaldate,
typeofattendanceforday AS typeofattendance,
count(*) AS count
FROM (SELECT
DATE(logindate) AS logindateindividual,
type AS typeofattendanceforday,
count(*) AS count
FROM log
WHERE logindate BETWEEN '2017-07-01 00:00:00' AND '2017-07-31 23:59:59'
GROUP BY CAST(logindate AS DATE), type, userid) AS data
GROUP BY data.logindateindividual;
但它没有提供最新类型。 如果用户有多个登录,那么它正在计算
我获得上述查询的结果是
loginlocaldate | typeofattendance | count |
-----------------------------------------------------
2017-07-01 | 1 | 5 |
-----------------------------------------------------
我的期望是
loginlocaldate | typeofattendance | count |
-----------------------------------------------------
2017-07-01 | 1 | 1 |
-----------------------------------------------------
2017-07-01 | 2 | 2 |
-----------------------------------------------------