如何获得客户提交的帖子的天数?
图片告诉我想得到什么。我不知道如何将mysql中的日期总结为天,有人帮忙吗?
需要php来做这些工作吗?
select ? from table where ?
SELECT customers_id, SUM(customers_id) as sum_days FROM table GROUP BY customers_id, DAY(date);
那应该这样做。
这是我的猜测:
SELECT `customers_id`, COUNT(DISTINCT(`date`)) as sum_days
FROM `table` GROUP BY `customers_id`
我在一张我正在修补的小桌子上试了一下,得到了以下结果:
SELECT author, entry_date FROM table;
+--------+------------+
| author | entry_date |
+--------+------------+
| 5 | 0000-00-00 |
| 8 | 0000-00-00 |
| 8 | 0000-00-00 |
| 8 | 2013-02-28 |
| 8 | 2013-02-28 |
| 8 | 2013-03-02 |
+--------+------------+
多田
SELECT author, COUNT(DISTINCT(entry_date)) as num_days
FROM table GROUP BY author ;
+--------+----------+
| author | num_days |
+--------+----------+
| 5 | 1 |
| 8 | 3 |
+--------+----------+
2 rows in set (0.00 sec)
另外,这是我之前在同一张桌子上回复的结果:
SELECT author, SUM(author) as sum_days FROM table
GROUP BY author, DAY(entry_date);
+--------+----------+
| author | sum_days |
+--------+----------+
| 5 | 5 |
| 8 | 16 |
| 8 | 8 |
| 8 | 16 |
+--------+----------+
4 rows in set (0.00 sec)