sql问题

#查询所有的--------------------------------------------------------
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报的错误


FineReportliangk 发布于 2018-10-16 11:37
悬赏:2 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共10回答
最佳回答
0
zsh331发布于2018-10-16 11:37(编辑于 2023-9-6 09:34)
555
最佳回答
0
zsh331发布于2018-10-16 11:43(编辑于 2023-9-6 09:34)
555
最佳回答
0
liangk发布于2018-10-16 11:44(编辑于 2023-9-6 09:34)
555
最佳回答
0
liangk发布于2018-10-16 11:45(编辑于 2023-9-6 09:34)
555
最佳回答
0
liangk发布于2018-10-16 11:55(编辑于 2023-9-6 09:34)
555
最佳回答
0
liangk发布于2018-10-16 11:56(编辑于 2023-9-6 09:34)
555
最佳回答
0
toor发布于2018-10-16 11:57(编辑于 2023-9-6 09:34)
555
最佳回答
0
zsh331发布于2018-10-16 11:58(编辑于 2023-9-6 09:34)
555
最佳回答
0
liangk发布于2018-10-16 11:58(编辑于 2023-9-6 09:34)
555
最佳回答
0
liangk发布于2018-10-17 08:40(编辑于 2023-9-6 09:34)
555
  • 0关注人数
  • 415浏览人数
  • 最后回答于:2018-10-17 08:40
    活动推荐 更多
    热门课程 更多
    返回顶部