我有users
表。我想生成当天加入的用户的报告。
问题是,我的DateJoined
字段是timestamp
字段,
查询如下:
SELECT COUNT(UserID) AS TOT FROM users GROUP BY DateJoined
不起作用,如何将其GROUP BY
仅用于日期部分,而不是DateJoined
字段的时间?
答案 0 :(得分:12)
您的代码:
SELECT
COUNT(UserID) AS TOT
FROM users
GROUP BY DateJoined
您应该改为:
SELECT
DATE(DateJoined),
COUNT(UserID) AS TOT
FROM users
GROUP BY DATE(DateJoined)
答案 1 :(得分:1)
尝试这样
SELECT COUNT(UserID) AS TOT FROM users GROUP BY CAST(DateJoined AS DATE)
OR
SELECT COUNT(UserID) AS TOT, FROM a_table GROUP BY DATE(DateJoined );
答案 2 :(得分:1)
使用像这样的查询
SELECT COUNT(UserID) AS TOT FROM users GROUP BY DATE(DateJoined)