从 MySQL date_format 中的 %m 和 %d 中删除前导零
Remove leading zeros from %m and %d in MySQL date_format
以下查询生成的日期类似于 2016, 01, 02
。如何让它从月份和日期中删除尾随零,使其看起来像这样 2016, 1, 2
?
SELECT DATE_FORMAT(earning_created, '%Y, %m, %d') AS day, SUM(earning_amount) AS amount
FROM earnings
WHERE earning_account_id = ?
GROUP BY DATE(earning_created)
ORDER BY earning_created
您可以使用 %c
格式化不带前导零的月份,并使用 %e
格式化月份中的日期:
SELECT DATE_FORMAT(earning_created, '%Y, %c, %e') AS day, -- Here!
SUM(earning_amount) AS amount
FROM earnings
WHERE earning_account_id = ?
GROUP BY DATE(earning_created)
ORDER BY earning_created
以下查询生成的日期类似于 2016, 01, 02
。如何让它从月份和日期中删除尾随零,使其看起来像这样 2016, 1, 2
?
SELECT DATE_FORMAT(earning_created, '%Y, %m, %d') AS day, SUM(earning_amount) AS amount
FROM earnings
WHERE earning_account_id = ?
GROUP BY DATE(earning_created)
ORDER BY earning_created
您可以使用 %c
格式化不带前导零的月份,并使用 %e
格式化月份中的日期:
SELECT DATE_FORMAT(earning_created, '%Y, %c, %e') AS day, -- Here!
SUM(earning_amount) AS amount
FROM earnings
WHERE earning_account_id = ?
GROUP BY DATE(earning_created)
ORDER BY earning_created