mysql计算本月的天数_Mysql已知年、月,求起始日期,本月天数
已知年月,求月初第一天,需要把字符串合并轉(zhuǎn)化成日期格式。
SELECT
STR_TO_DATE(CONCAT(a.`year`,'-',a.`month`,'-',1),'%Y-%m-%d') as 'start_day',
LAST_DAY(STR_TO_DATE(CONCAT(a.`year`,'-',a.`month`,'-',1),'%Y-%m-%d')) as 'end_day',
date(@date:=DATE_ADD(@date:=STR_TO_DATE(CONCAT(a.`year`,'-',a.`month`,'-',1),'%Y-%m-%d'),
INTERVAL e.help_topic_id day)) 'date',
a.`year`,a.`month`,a.carline_id,a.amount,
DAY(LAST_DAY(STR_TO_DATE(CONCAT(a.`year`,'-',a.`month`,'-',1),'%Y-%m-%d'))) as 'days'
FROM salesguides a
JOIN help_topic e
WHERE a.`year`=2020 and a.`month`=5 and a.shop_id=1 and a.carline_id=10
and e.help_topic_id
總結(jié)
以上是生活随笔為你收集整理的mysql计算本月的天数_Mysql已知年、月,求起始日期,本月天数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 科技创新的重要性和作用
- 下一篇: 如何使睫毛变长