Mysql 查询近6个月每个月有多少天:
SELECT
DATE_FORMAT(DATE_ADD(NOW(),INTERVAL-(CAST( help_topic_id AS SIGNED INTEGER )) MONTH ), '%Y-%m') as months,
DAY(LAST_DAY(CONCAT(DATE_FORMAT(DATE_ADD(NOW(),INTERVAL-(CAST( help_topic_id AS SIGNED INTEGER )) MONTH ), '%Y-%m'),'-01'))) AS days_in_month
FROM mysql.help_topic
WHERE help_topic_id <6 ORDER BY months asc
效果: