顧客が投稿した日数を取得する方法は?
写真は私が何を手に入れたいかを物語っています。mysql で日付を日数として合計する方法がわかりません。
これらの仕事をするためにphpが必要ですか?
select ? from table where ?
これが私の推測です:
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)
SELECT customers_id, SUM(customers_id) as sum_days FROM table GROUP BY customers_id, DAY(date);
それはそれを行う必要があります。