WageStatsMinidaoDao_deptWageStatsData.sql 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. SELECT yearmonth,pjtId,deptId,unitPeopleTotal
  2. ,convert(pre_tax_mone - IFNULL(Apay,Acount/:params.daycount * (pre_tax_mone + compro + comsoc)) + IFNULL(Bpay,Bcount/:params.daycount * (pre_tax_mone + compro + comsoc)),decimal(10,2)) wagePayTotal
  3. from (
  4. SELECT o.*,
  5. (
  6. SELECT COUNT(*) from t_bus_user_attendance_detail WHERE borrowstatus ='1' and borrowspid = o.pjtId and borrowsdepartid = o.deptId and DATE_FORMAT(ymd_date,"%Y-%m")=:params.yearmonth
  7. ) Bcount,
  8. (
  9. SELECT sum(day_pay) from t_bus_user_attendance_detail WHERE borrowstatus ='1' and borrowspid = o.pjtId and borrowsdepartid = o.deptId and DATE_FORMAT(ymd_date,"%Y-%m")=:params.yearmonth
  10. ) Bpay
  11. from
  12. (
  13. SELECT a.monthly yearmonth,a.pid pjtId,a.departid deptId,a.pmId,COUNT(*) unitPeopleTotal,SUM(a.Acount) Acount,SUM(a.Apay) Apay,SUM(pre_tax_mone) pre_tax_mone,SUM(compro) compro,SUM(comsoc) comsoc
  14. FROM
  15. (
  16. SELECT uat.*,
  17. (
  18. SELECT COUNT(*) from t_bus_user_attendance_detail WHERE attendance_id=uat.id and borrowstatus ='1'
  19. ) Acount,
  20. (
  21. SELECT sum(day_pay) from t_bus_user_attendance_detail WHERE attendance_id=uat.id and borrowstatus ='1'
  22. ) Apay
  23. FROM(
  24. SELECT uw.userid,uw.monthly,uw.pre_tax_mone,IFNULL(uw.com_provident_fund_debit,0) compro ,IFNULL(uw.com_social_security_debit,0) comsoc ,uw.pjt_id pid,uw.belong_unitid departId,uat.id,d.dept_proj_managerid pmId
  25. from t_bus_user_wage uw
  26. LEFT JOIN t_s_depart d
  27. ON uw.pjt_id = d.ID
  28. LEFT JOIN t_bus_user_attendance_total uat
  29. ON uw.userid = uat.user_id and uat.yearmonth =:params.yearmonth
  30. WHERE uw.monthly =:params.yearmonth and (d.org_type = 3 or d.org_type = 5)
  31. ) uat
  32. WHERE uat.monthly =:params.yearmonth AND uat.pid != ''
  33. )a
  34. GROUP BY pid,departid
  35. ) o
  36. )re
  37. order by wagePayTotal desc