我想将注释字段作为一个字符串返回,例如开头的日期。
2015-01-13 Important Note!, 2014-05-04 Please Read
示例说明表:
+----+---------+-----------------+---------------------+
| id | user_id | note | created_at |
+----+---------+-----------------+---------------------+
| 2 | 2 | Important Note! | 2015-01-13 18:28:01 |
| 3 | 2 | Please Read | 2014-05-04 11:18:52 |
| 4 | 3 | Who Left This? | 2011-01-19 12:14:57 |
+----+---------+-----------------+---------------------+
我有以下SQL但我需要在created_at列中包含日期部分:
SELECT u.name, GROUP_CONCAT(DISTINCT n.note) AS notes
FROM user u
LEFT JOIN notes n ON n.user_id = u.id
GROUP BY u.id
答案 0 :(得分:0)
刚刚解决了这个问题:
SELECT u.name, GROUP_CONCAT(DISTINCT DATE_FORMAT(n.created_at, '%e %b %y'), ' ', n.note) AS notes
FROM user u
LEFT JOIN notes n ON n.user_id = u.id
GROUP BY u.id