UserStatsMinidaoDao_userStatsPdData.sql 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. SELECT
  2. e.*
  3. <#if (userEntity.attType)?? && userEntity.attType != 0>
  4. ,(
  5. SELECT earlymonth_total
  6. from t_bus_dept_user_statistics pus
  7. WHERE pus.pjt_id=e.pid and pus.dept_id = e.deptId
  8. and pus.yearmonth=e.minyearmonth
  9. ) earlyMonthTotal
  10. ,(
  11. SELECT endmonth_total
  12. from t_bus_dept_user_statistics pus
  13. WHERE pus.pjt_id=e.pid and pus.dept_id = e.deptId
  14. and pus.yearmonth=e.maxyearmonth
  15. ) endMonthTotal
  16. </#if>
  17. FROM
  18. (
  19. SELECT u.pjt_id pid,d.description pName,u.dept_id deptId,d1.departname pidName,u.yearmonth
  20. <#if (userEntity.attType)?? && userEntity.attType != 0>
  21. ,MAX(yearmonth) maxyearmonth,MIN(yearmonth) minyearmonth
  22. ,sum(u.entry_total) entryTotal,sum(u.leave_total) leaveTotal
  23. ,convert(avg(u.flow_proportion),decimal(10,2)) flowProportion
  24. </#if>
  25. <#if (userEntity.attType)?? && userEntity.attType == 0>
  26. ,u.earlymonth_total earlyMonthTotal ,u.endmonth_total endMonthTotal
  27. ,u.entry_total entryTotal,u.leave_total leaveTotal
  28. ,u.flow_proportion flowProportion
  29. </#if>
  30. from t_bus_dept_user_statistics u
  31. LEFT JOIN t_s_depart d
  32. ON u.pjt_id = d.ID
  33. LEFT JOIN t_s_depart d1
  34. ON u.dept_id = d1.ID
  35. where 1=1
  36. <#if (userEntity.attType)?? && userEntity.attType == 2>
  37. and u.yearmonth like CONCAT('%', :userEntity.attYear ,'%')
  38. </#if>
  39. <#if (userEntity.attType)?? && userEntity.attType != 2>
  40. <#if ( userEntity.yearMonthList )?? && userEntity.yearMonthList ?size gt 0>
  41. and u.yearmonth in(
  42. <#list userEntity.yearMonthList as item>
  43. '${item}'
  44. <#if item_has_next>,</#if>
  45. </#list>
  46. )
  47. </#if>
  48. </#if>
  49. <#if (userEntity.pid)??>
  50. and u.pjt_id =:userEntity.pid
  51. </#if>
  52. GROUP BY u.dept_id
  53. ) e
  54. order by flowProportion desc