SET @rownum=0; SELECT @rownum:=@rownum+1 序号, c.dept_name 单位名称, IFNULL(c.c1,0)+IFNULL(d.c2,0) 人数, IFNULL(c.s1,0)+IFNULL(d.s2,0) 期初余额, IFNULL(d.c2,0) 人数, IFNULL(d.s2,0) 本月支取, IFNULL(e.c3,0) 人数, IFNULL(e.s3,0) 累计支取, IFNULL(c.c1,0)+IFNULL(d.c2,0)- IFNULL(d.c2,0) 人数, IFNULL(c.s1,0)+IFNULL(d.s2,0)- IFNULL(d.s2,0) 期末余额 FROM (SELECT b.dept_name,IFNULL(COUNT(a.status),0) c1,IFNULL(SUM(a.distribution_money),0) s1 FROM t_interest_distribution_details_info a LEFT JOIN t_interest_account_emp_info b ON a.emp_code=b.emp_code WHERE a.valid_flag =1 AND a.status!=3 GROUP BY b.dept_name) c LEFT JOIN (SELECT b.dept_name,IFNULL(COUNT(a.status),0) c2,IFNULL(SUM(a.distribution_money),0) s2 FROM t_interest_distribution_details_info a LEFT JOIN t_interest_account_emp_info b ON a.emp_code=b.emp_code WHERE a.valid_flag=1 AND DATE_FORMAT(a.status_date,'%Y-%m')>=DATE_FORMAT(NOW()-1,'%Y-%m') AND DATE_FORMAT(a.status_date,'%Y-%m')<=DATE_FORMAT(NOW(),'%Y-%m') AND a.status=3 GROUP BY b.dept_name) d ON c.dept_name=d.dept_name LEFT JOIN (SELECT b.dept_name,IFNULL(COUNT(a.status),0) c3,IFNULL(SUM(a.distribution_money),0) s3 FROM t_interest_distribution_details_info a LEFT JOIN t_interest_account_emp_info b ON a.emp_code=b.emp_code WHERE a.valid_flag=1 AND a.status=3 AND DATE_FORMAT(a.status_date,'%Y')=DATE_FORMAT(NOW(),'%Y') GROUP BY b.dept_name) e ON c.dept_name=e.dept_name |
最佳回答 |
||||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|