当前位置:   article > 正文

mysql多表关联、sum、GROUP BY函数使用_mysql sum group

mysql sum group
  1. SELECT
  2. '01在职' 状态,
  3. a.A0100,
  4. a.A0191,
  5. a.A01BE,
  6. -- any_value(a.A0191),
  7. -- any_value(a.A01BE),
  8. a.A0101,
  9. any_value(a.E01A1),
  10. any_value(a.A0141),
  11. any_value(a.A0142),
  12. any_value(a.A01BN),
  13. sum(b.A58DB+b.A58AB+b.A5873+b.A58BN+b.A58CA) as 基岗工资,
  14. sum(b.A58BE) as 预发奖金,
  15. sum(b.A5870) as 已发薪资(合计),
  16. sum(b.A58DB+b.A58AB) as 基岗工资1,
  17. sum(b.A58BC+f.A0GAK+f.A0GAL+f.A0GAM) as 应发奖金,
  18. sum(b.A58AD) as 应发年薪(合计),
  19. sum(b.A58CF) as 驻外补贴(月度),
  20. sum(f.A0GAN) as 驻外补贴(年度),
  21. sum(b.A58CM) as 特殊补贴,
  22. sum(b.A58BM) as 考核系数,
  23. ( CASE WHEN a.A01BE <> '04' and a.A01BE <> '05' THEN sum(b.A58BC+f.A0GAK+f.A0GAL+f.A0GAM)/sum(b.A58BM) ELSE '' END ) AS 核定奖金,
  24. ( CASE WHEN a.A01BE <> '04' and a.A01BE <> '05' THEN sum(b.A58BC+f.A0GAK+f.A0GAL+f.A0GAM)/sum(b.A58BM) ELSE '' END ) AS 核定年薪,
  25. -- ''as 核定奖金,
  26. -- ''as 核定年薪,
  27. ''as 工作月数,
  28. ''as 核定年薪(月折算),
  29. ''as 应发年薪(月折算),
  30. any_value(d.A55AN) as 最新基本工资,
  31. any_value(d.A5530) as 最新岗位工资,
  32. any_value(d.A55BB) as 最新预发奖金,
  33. any_value(d.A55AS) as 最新薪等,
  34. any_value(d.A55AR) as 最新薪级,
  35. any_value(b.A58CJ) as 最新应扣事假工资,
  36. any_value(b.A58AY) as 最新税前其他扣款,
  37. any_value(b.A58CK) as 最新应扣病假工资,
  38. any_value(b.A58CL) as 最新应扣事(病)假奖金,
  39. any_value(b.A58CG) as 最新应扣驻外补贴,
  40. any_value(A58Z0) as fxsj
  41. -- any_value(DATE_FORMAT(b.A58Z0,'%m') yf)
  42. -- DATE_FORMAT(b.A58Z0,'%Y') nf, -- 年度
  43. -- DATE_FORMAT(b.A58Z0,'%m') yf -- 期间
  44. FROM
  45. usra01 a
  46. LEFT JOIN ( SELECT a0100, max(I9999) as i99991 FROM usra55 GROUP BY a0100 ) AS c ON a.a0100 = c.a0100
  47. LEFT JOIN usra55 d on d.a0100=c.a0100 and c.i99991=d.I9999
  48. LEFT JOIN ( SELECT a0100, max(I9999) as i99992 FROM usra58 GROUP BY a0100 ) AS e ON a.a0100 = e.a0100
  49. LEFT JOIN usra58 b ON b.A0100 = e.A0100 and e.i99992=b.I9999
  50. LEFT JOIN (select f1.A0100,f1.A0GAK,f1.A0GAL,f1.A0GAM,f1.A0GAN from usra0g f1,usra58 f2 where f1.A0100=f2.A0100 and f2.A58DW LIKE 'Z60%' ) f ON a.A0100 = f.A0100
  51. where a.B0110 LIKE 'Z60%' or a.A0144='19920003'
  52. GROUP BY a.a0100,a.a0101,a.A0191,a.A01BE
  53. union
  54. SELECT
  55. '02离职' 状态,
  56. a.A0100,
  57. a.A0191,
  58. a.A01BE,
  59. -- any_value(a.A0191),
  60. -- any_value(a.A01BE),
  61. a.A0101,
  62. any_value(a.E01A1),
  63. any_value(a.A0141),
  64. any_value(a.A0142),
  65. any_value(a.A01BN),
  66. sum(b.A58DB+b.A58AB+b.A5873+b.A58BN+b.A58CA) as 基岗工资,
  67. sum(b.A58BE) as 预发奖金,
  68. sum(b.A5870) as 已发薪资(合计),
  69. sum(b.A58DB+b.A58AB) as 基岗工资1,
  70. sum(b.A58BC+f.A0GAK+f.A0GAL+f.A0GAM) as 应发奖金,
  71. sum(b.A58AD) as 应发年薪(合计),
  72. sum(b.A58CF) as 驻外补贴(月度),
  73. sum(f.A0GAN) as 驻外补贴(年度),
  74. sum(b.A58CM) as 特殊补贴,
  75. sum(b.A58BM) as 考核系数,
  76. ( CASE WHEN a.A01BE <> '04' and a.A01BE <> '05' THEN sum(b.A58BC+f.A0GAK+f.A0GAL+f.A0GAM)/sum(b.A58BM) ELSE '' END ) AS 核定奖金,
  77. ( CASE WHEN a.A01BE <> '04' and a.A01BE <> '05' THEN sum(b.A58BC+f.A0GAK+f.A0GAL+f.A0GAM)/sum(b.A58BM) ELSE '' END ) AS 核定年薪,
  78. -- ''as 核定奖金,
  79. -- ''as 核定年薪,
  80. ''as 工作月数,
  81. ''as 核定年薪(月折算),
  82. ''as 应发年薪(月折算),
  83. any_value(d.A55AN) as 最新基本工资,
  84. any_value(d.A5530) as 最新岗位工资,
  85. any_value(d.A55BB) as 最新预发奖金,
  86. any_value(d.A55AS) as 最新薪等,
  87. any_value(d.A55AR) as 最新薪级,
  88. any_value(b.A58CJ) as 最新应扣事假工资,
  89. any_value(b.A58AY) as 最新税前其他扣款,
  90. any_value(b.A58CK) as 最新应扣病假工资,
  91. any_value(b.A58CL) as 最新应扣事(病)假奖金,
  92. any_value(b.A58CG) as 最新应扣驻外补贴,
  93. any_value(A58Z0) as fxsj
  94. -- any_value(DATE_FORMAT(b.A58Z0,'%m') yf)
  95. -- DATE_FORMAT(b.A58Z0,'%Y') nf, -- 年度
  96. -- DATE_FORMAT(b.A58Z0,'%m') yf -- 期间
  97. FROM
  98. reta01 a
  99. LEFT JOIN ( SELECT a0100, max(I9999) as i99991 FROM reta55 GROUP BY a0100 ) AS c ON a.a0100 = c.a0100
  100. LEFT JOIN reta55 d on d.a0100=c.a0100 and c.i99991=d.I9999
  101. LEFT JOIN ( SELECT a0100, max(I9999) as i99992 FROM reta58 GROUP BY a0100 ) AS e ON a.a0100 = e.a0100
  102. LEFT JOIN reta58 b ON b.A0100 = e.A0100 and e.i99992=b.I9999
  103. LEFT JOIN (select f1.A0100,f1.A0GAK,f1.A0GAL,f1.A0GAM,f1.A0GAN from reta0g f1,reta58 f2 where f1.A0100=f2.A0100 and f2.A58DW LIKE 'Z60%' ) f ON a.A0100 = f.A0100
  104. where a.B0110 LIKE 'Z60%'
  105. GROUP BY a.a0100,a.a0101,a.A0191,a.A01BE

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/986676
推荐阅读
相关标签
  

闽ICP备14008679号