满意答案
不考虑 “天”的因素:
select if(month(d2)-month(d1)>0,
concat(year(d2)-year(d1),'年',month(d2)-month(d1),'月'),
concat(year(d2)-year(d1)-1,'年',month(d2)-month(d1)+12,'月')) as r from xxxxx
----------------------------------------------------------------------------------------------------------
例子:
d1='2013-05-13'
d2='2014-07-13'
select if(month('2014-07-13')-month('2013-05-13')>0,
concat(year('2014-07-13')-year('2013-05-13'),'年',month('2014-07-13')-month('2013-05-13'),'月'),
concat(year('2014-07-13')-year('2013-05-13')-1,'年',month('2014-07-13')-month('2013-05-13')+12,'月')) as r
结果:1年2月
=================================================================
d1='2013-05-13'
d2='2014-01-13'
select if(month('2014-01-13')-month('2013-05-13')>0,
concat(year('2014-01-13')-year('2013-05-13'),'年',month('2014-01-13')-month('2013-05-13'),'月'),
concat(year('2014-01-13')-year('2013-05-13')-1,'年',month('2014-01-13')-month('2013-05-13')+12,'月')) as r
结果:0年8月
00分享举报
博客介绍了在MySQL中计算两个月份之间差值的方法,不考虑“天”的因素,给出了相应的SQL语句,并通过两个具体例子展示了计算过程和结果,如计算'2013 - 05 - 13'和'2014 - 07 - 13'、'2013 - 05 - 13'和'2014 - 01 - 13'的月份差值。
1121

被折叠的 条评论
为什么被折叠?



