我有以下结构
ID DATE(DATETIME) TID
1 2012-04-01 23:23:23 8882
我正在尝试计算行数并按每月匹配 TID = 8882 的每一天对它们进行分组
谢谢
您可以使用DAY功能进行分组:
SELECT DAY(Date), COUNT(*)
FROM table
WHERE TID = 8882
GROUP BY DAY(Date)
不确定您所说的月份中的某天是什么意思——您想将 2 月 1 日与 3 月 1 日归为一组吗?或者你只是说约会?假设后者,这个怎么样:
SELECT DATE(date) as d,count(ID) from TABLENAME where TID=8882 GROUP by d;
试试这个查询:
SELECT COUNT(id), DAY(dat), MONTH(dat), YEAR(dat)
FROM table
WHERE TID=8882
GROUP BY YEAR(dat), MONTH(dat), DAY(dat);
尝试这个:
SELECT DAY(date) AS `DAY`, COUNT(1) AS `COUNT` FROM
table1
WHERE TID = 8882
GROUP BY DAY(date)
计算每个日期:
SELECT date(created_at), COUNT(*)
FROM message_requests
GROUP BY date(created_at)