UserStatsMinidaoDao_userStatsData.sql 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. SELECT
  2. e.*
  3. <#if (userEntity.attType)?? && userEntity.attType != 0>
  4. ,(
  5. SELECT earlymonth_total
  6. from t_bus_proj_user_statistics pus
  7. WHERE pus.pjt_id=e.pid
  8. and pus.yearmonth=e.minyearmonth
  9. ) earlyMonthTotal
  10. ,(
  11. SELECT endmonth_total
  12. from t_bus_proj_user_statistics pus
  13. WHERE pus.pjt_id=e.pid
  14. and pus.yearmonth=e.maxyearmonth
  15. ) endMonthTotal
  16. </#if>
  17. FROM
  18. (
  19. SELECT u.pjt_id pid,d.description pName,bu.realname 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_proj_user_statistics u
  31. LEFT JOIN t_s_depart d
  32. ON u.pjt_id = d.ID
  33. LEFT JOIN t_s_base_user bu
  34. ON u.pm_id = bu.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.attType)?? && userEntity.attType != 0>
  50. GROUP BY u.pjt_id
  51. </#if>
  52. ) e
  53. order by flowProportion desc