请帮我转换我的查询,该查询返回以月为单位的数字格式。我想把它转换为像1月这样的词。
这是我的问题:
SELECT
MONTH(tbl_check_up.check_up_date) AS datemonths
FROM
tbl_clinics
INNER JOIN
tbl_queue ON tbl_clinics.clinic_id = tbl_queue.clinic_id
INNER JOIN
tbl_check_up ON tbl_queue.queue_id = tbl_check_up.queue_id
WHERE
tbl_clinics.user_id = 102
AND YEAR(tbl_check_up.check_up_date) = 2017
GROUP BY
MONTH(tbl_check_up.check_up_date)
我的查询输出是:
--------------
| datemonths |
--------------
| 2 |
| 4 |
|____________|
答案 0 :(得分:1)
尝试
DATE_FORMAT(date_column,'%M')
你的sql将如下所示
SELECT
DATE_FORMAT(tbl_check_up.check_up_date,'%M') AS datemonths
FROM
tbl_clinics
INNER JOIN tbl_queue ON tbl_clinics.clinic_id = tbl_queue.clinic_id
INNER JOIN tbl_check_up ON tbl_queue.queue_id = tbl_check_up.queue_id
WHERE tbl_clinics.user_id = 102 AND YEAR(tbl_check_up.check_up_date) = 2017
GROUP BY DATE_FORMAT(tbl_check_up.check_up_date,'%M')
答案 1 :(得分:0)
是的,请使用STR_TO_DATE()
。阅读它here。