按用户名分组时,查询返回错误的结果

时间:2015-04-13 05:43:33

标签: mysql

我想显示每天的结果数量(登录次数)。我的查询问题是它返回错误的值。我认为问题在于分组。有人知道问题出在哪里吗?

同样logaction行可以包含1-4中的数字,所以我想计算每天1,2,3和4中有多少行。

以下是我正在使用的代码:

SELECT  username, DATE( Vrijeme) AS Datum, COUNT( logaction ) AS total
FROM user_login_action
WHERE DATE( Datum ) >=  '2015-04-06'
AND DATE( Datum ) <=  '2015-04-12'
AND username !=  ''
GROUP BY DATE( Datum ) , username

1 个答案:

答案 0 :(得分:3)

您的查询中存在以下问题:
DATE(Vrijeme) AS DatumSELECT DATE(Datum)WHEREGROUP BY使用SELECT username, DATE(Vrijeme) AS Datum, COUNT( logaction ) AS total FROM user_login_action WHERE DATE(Vrijeme) >= '2015-04-06' AND DATE(Vrijeme) <= '2015-04-12' AND username != '' GROUP BY DATE(Vrijeme), username

此查询是否会返回您想要的结果:

{{1}}