当前位置:Gxlcms > PHP教程 > 一条SQL语句怎么求环比!这个月简历数减去上个月的(如图)

一条SQL语句怎么求环比!这个月简历数减去上个月的(如图)

时间:2021-07-01 10:21:17 帮助过:33人阅读

一条SQL语句如何求环比!这个月简历数减去上个月的(如图)

【这个月简历数】-【上个月的简历数】=【环比数】(如图)

sql语句如何写?
SELECT DATE_FORMAT(m_adddate,'%m') as month,count(m_id) as zong,DATE_FORMAT(m_adddate,'%Y') as year from job_myreceive where DATE_FORMAT(m_adddate,'%Y')=2011 GROUP BY DATE_FORMAT(m_adddate,'%m');

分享到:


------解决方案--------------------
嗯,这样写清楚些
SELECT DATE_FORMAT(a.m_adddate,'%Y%m') as Ym, count(*) as `当月`,
(select count(*) from job_myreceive where
DATE_FORMAT(a.m_adddate,'%Y%m') = DATE_FORMAT(DATE_add(m_adddate,INTERVAL 1 MONTH),'%Y%m')
) as 上月
FROM job_myreceive a group by 1

Ym 当月 上月
201012 6 0
201101 2 6
201105 1 0
201107 2 0
201112 1 0
201305 1 0

人气教程排行