1, simple, monthly statistics quantity
SELECT ' %y-%m ' as Month COUNT (* as Sum from Pt_user GROUP bymonth;
2, by the monthly cumulative statistical data
SELECTA.Month,SUM(b.total) as Total from ( SELECTDate_format (Create_date,'%y-%m') as Month,SUM(sum) as Total from ( SELECTCreate_date, Date_format (Create_date,'%y-%m') as Month , COUNT(*) as sum fromPt_userGROUP by Month) PtuserGROUP by Month) AJOIN ( SELECTDate_format (Create_date,'%y-%m') as Month,SUM(sum) as Total from ( SELECTCreate_date, Date_format (Create_date,'%y-%m') as Month , COUNT(*) as sum fromPt_userGROUP by Month) PtuserGROUP by Month) b onA.MONTH >=B.MONTHGROUP byA.MONTHORDER byA.Month;
3, multi-field monthly cumulative statistics (eg: Cumulative monthly growth per tenant statistics)
SELECTA.ORGAN_ID, A.Month,SUM(b.total) as Total from ( SELECTorgan_id, Date_format (Create_time,'%y-%m') as Month , SUM(sum) as Total from ( SELECTorgan_id, Create_time, Date_format (Create_time,'%y-%m') as Month , COUNT(*) as sum fromPt_userGROUP by Month) PtuserGROUP byORGAN_ID,Month) AJOIN ( SELECTorgan_id, Date_format (Create_time,'%y-%m') as Month , SUM(sum) as Total from ( SELECTorgan_id, Create_time, Date_format (Create_time,'%y-%m') as Month , COUNT(*) as sum fromPt_userGROUP by Month) PtuserGROUP byORGAN_ID,Month) b ona.organ_id=b.organ_id andA.MONTH >=B.MONTHGROUP byA.MONTHORDER byA.ORGAN_ID, A.Month;
SQL Monthly count and monthly cumulative count