UserStatsMinidaoDao_deptUserStatsData.sql 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. SELECT *,earlymonthTotal+entryTotal-leaveTotal endmonthTotal,IFNULL(CONVERT(e.leaveTotal/e.earlymonthTotal*100,decimal(10,2)),0) flowProportion ,:param.yearmonth yearmonth
  2. from (
  3. SELECT dept.pjtid,dept.pmid,emt.deptId,IFNULL(dus.endmonth_total,IFNULL(emt.earlymonthTotal,0)) as earlymonthTotal,IFNULL(et.entryTotal,0) entryTotal,IFNULL(lt.leaveTotal,0) leaveTotal
  4. from (
  5. SELECT uo.org_id deptId ,COUNT(*) as earlymonthTotal
  6. from t_bus_user_personnel up
  7. LEFT JOIN t_s_user_org uo
  8. ON up.userid = uo.user_id and uo.`status`=0 and uo.ifpluralism = 0
  9. LEFT JOIN t_s_depart d
  10. ON d.ID = uo.org_id
  11. LEFT JOIN t_s_base_user u
  12. ON up.userid = u.ID
  13. WHERE
  14. (up.position_status = 1 or up.position_status = 2) and up.contract_stime < :param.earlymonth and uo.org_id != '' and u.delete_flag = 0
  15. GROUP BY uo.org_id
  16. ) emt
  17. LEFT JOIN
  18. (
  19. SELECT uw.belong_unitid deptId, uw.pjt_id pjtid,d.dept_proj_managerid pmid
  20. from t_bus_user_personnel bup
  21. LEFT JOIN t_bus_user_wage uw
  22. ON bup.userid = uw.userid and uw.monthly =:param.yearmonth
  23. LEFT JOIN t_s_depart d
  24. ON uw.pjt_id = d.ID
  25. WHERE uw.belong_unitid != '' and uw.pjt_id !='' and (d.org_type = 3 or d.org_type = 5)
  26. GROUP BY uw.pjt_id,uw.belong_unitid
  27. ) dept ON dept.deptId = emt.deptId
  28. LEFT JOIN
  29. (
  30. SELECT up.userid,uo.org_id deptId ,COUNT(*) as entryTotal
  31. from t_bus_user_personnel up
  32. LEFT JOIN t_s_user_org uo
  33. ON up.userid = uo.user_id and uo.`status`=0
  34. WHERE
  35. (up.position_status = 1 or up.position_status = 2) and (up.contract_stime >= :param.earlymonth and up.contract_stime <=:param.endmonth)
  36. GROUP BY uo.org_id
  37. ) et ON emt.deptId = et.deptId
  38. LEFT JOIN
  39. (
  40. SELECT up.userid,uo.org_id deptId ,COUNT(*) as leaveTotal
  41. FROM t_bus_user_personnel up
  42. LEFT JOIN t_bus_leave l
  43. ON up.userid = l.userid
  44. LEFT JOIN t_s_user_org uo
  45. ON up.userid = uo.user_id and uo.`status`=0
  46. WHERE l.leave_date >= :param.earlymonth and l.leave_date <=:param.endmonth and l.delete_flag =0
  47. GROUP BY uo.org_id
  48. ) lt ON emt.deptId = lt.deptId
  49. LEFT JOIN t_bus_dept_user_statistics dus
  50. ON emt.deptId = dus.dept_id and dus.yearmonth=:param.beforemotn
  51. ) e
  52. order by flowProportion desc