#查询所有的-------------------------------------------------------- SELECT t1.dept_name 单位名称, IFNULL((t2.c1+t3.c2+t5.c4),0) 人数, IFNULL((t2.s1+t3.s2+t5.s4),0) 期初余额, IFNULL(t6.c5,0) 人数, IFNULL(t6.s5,0) 本期支取, IFNULL(t4.c3,0) 人数, IFNULL(t4.s3,0) 本年支取, IFNULL((t2.c1+t3.c2+t5.c4-t6.c5),0) 人数, IFNULL((t2.s1+t3.s2+t5.s4-t6.s5),0) 期末余额 FROM (SELECT * FROM t_interest_distribution_details_info a LEFT JOIN t_interest_account_emp_info b ON a.emp_code=b.emp_code GROUP BY b.dept_name) t1 LEFT JOIN #所有未核销------------------------------------------------------------------------------- (SELECT 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) t2 ON t1.dept_name=t2.dept_name LEFT JOIN #时间段内已核销----------------------------------------------------------------------------- (SELECT 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 a.status=3 AND DATE_FORMAT(a.status_date,'%Y-%m')>='2018-01' AND DATE_FORMAT(a.status_date,'%Y-%m')<='2018-03' GROUP BY b.dept_name) t3 ON t1.dept_name=t3.dept_name LEFT JOIN #本年累计------------------------------------------------------------------------------- (SELECT 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 YEAR(a.status_date)=YEAR(NOW()) GROUP BY b.dept_name) t4 ON t1.dept_name=t4.dept_name LEFT JOIN #到本期时间段内已核销的----------------------------------------------------------------- (SELECT IFNULL(COUNT(a.status),0) c4,IFNULL(SUM(a.distribution_money),0) s4 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-%m')>='2018-01' AND DATE_FORMAT(a.status_date,'%Y-%m')<=DATE_FORMAT(NOW(),'%Y-%m') GROUP BY b.dept_name) t5 ON t1.dept_name=t5.dept_name LEFT JOIN #本期(本月)支取------------------------------------------------------------------------------- (SELECT IFNULL(COUNT(a.status),0) c5,IFNULL(SUM(a.distribution_money),0) s5 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-%m' ) = DATE_FORMAT( CURDATE() , '%Y-%m' ) GROUP BY b.dept_name) t6 ON t1.dept_name=t6.dept_name #-------------------------------------------------------------------------------------------------------------------------------------------------------- 这是运行sql报的错误 ![]() |
最佳回答 |
||||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|