Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.95 KB | None | 0 0
  1. WITH statq1 AS (
  2. SELECT a.BUNKE_ID, b.BUNKENAVN, "naju", "kani", "mada", "asbi", "megh", "limo", "dool", "elmo", "makv", "haho", "chbh", "alal", "sibj", "miho", "juat", "kapo", "loje", "beni", "mean" FROM (
  3. SELECT * FROM (
  4. SELECT * FROM DSS_MAMA
  5. UNPIVOT INCLUDE NULLS ( BUNKE_COUNT FOR BUNKE_ID IN (
  6. bunke_id_4206,
  7. bunke_id_4207,
  8. bunke_id_4208,
  9. bunke_id_4210,
  10. bunke_id_4243,
  11. bunke_id_4238,
  12. bunke_id_4217,
  13. bunke_id_4032,
  14. bunke_id_4213,
  15. bunke_id_4214,
  16. bunke_id_4215,
  17. bunke_id_4216,
  18. bunke_id_4221,
  19. bunke_id_4222,
  20. bunke_id_4223,
  21. bunke_id_4224,
  22. bunke_id_4225,
  23. bunke_id_4226,
  24. bunke_id_4227,
  25. bunke_id_4228,
  26. bunke_id_4219,
  27. bunke_id_4220,
  28. bunke_id_4234,
  29. bunke_id_4237,
  30. bunke_id_4241,
  31. bunke_id_4261,
  32. bunke_id_4211,
  33. bunke_id_4233,
  34. bunke_id_4209,
  35. bunke_id_4239,
  36. bunke_id_4240,
  37. bunke_id_2405,
  38. bunke_id_2423,
  39. bunke_id_3497,
  40. bunke_id_4005,
  41. bunke_id_4006,
  42. bunke_id_4012,
  43. bunke_id_4100,
  44. bunke_id_4101,
  45. bunke_id_4170,
  46. bunke_id_4172,
  47. bunke_id_4174,
  48. bunke_id_4191,
  49. bunke_id_4192,
  50. bunke_id_4193,
  51. bunke_id_4273,
  52. bunke_id_4357,
  53. bunke_id_4358,
  54. bunke_id_4359,
  55. bunke_id_4360
  56. )))
  57. PIVOT (SUM(nvl(bunke_count,0)) FOR BRUGERE IN ('naju' AS "naju", 'kani' AS "kani", 'mada' AS "mada", 'asbi' AS "asbi", 'megh' AS "megh", 'limo' AS "limo", 'dool' AS "dool", 'elmo' AS "elmo", 'makv' AS "makv", 'haho' AS "haho", 'chbh' AS "chbh", 'alal' AS "alal", 'sibj' AS "sibj", 'miho' AS "miho", 'juat' AS "juat", 'kapo' AS "kapo", 'loje' AS "loje", 'beni' AS "beni", 'mean' AS "mean"))) a
  58. LEFT JOIN BUNKER b ON LTRIM(a.BUNKE_ID, 'BUNKE_ID_') = b.BUNKE_ID
  59. --ORDER BY a.BUNKE_ID DESC
  60. )
  61. ,
  62. statq2 AS (SELECT a.BUNKE_ID, b.BUNKENAVN, "legr", "salu", "chba", "jath", "emjo", "mama" FROM (
  63. SELECT * FROM (
  64. SELECT * FROM DSS_MAMA
  65. UNPIVOT INCLUDE NULLS ( BUNKE_COUNT FOR BUNKE_ID IN (
  66. bunke_id_4206,
  67. bunke_id_4207,
  68. bunke_id_4208,
  69. bunke_id_4210,
  70. bunke_id_4243,
  71. bunke_id_4238,
  72. bunke_id_4217,
  73. bunke_id_4032,
  74. bunke_id_4213,
  75. bunke_id_4214,
  76. bunke_id_4215,
  77. bunke_id_4216,
  78. bunke_id_4221,
  79. bunke_id_4222,
  80. bunke_id_4223,
  81. bunke_id_4224,
  82. bunke_id_4225,
  83. bunke_id_4226,
  84. bunke_id_4227,
  85. bunke_id_4228,
  86. bunke_id_4219,
  87. bunke_id_4220,
  88. bunke_id_4234,
  89. bunke_id_4237,
  90. bunke_id_4241,
  91. bunke_id_4261,
  92. bunke_id_4211,
  93. bunke_id_4233,
  94. bunke_id_4209,
  95. bunke_id_4239,
  96. bunke_id_4240,
  97. bunke_id_2405,
  98. bunke_id_2423,
  99. bunke_id_3497,
  100. bunke_id_4005,
  101. bunke_id_4006,
  102. bunke_id_4012,
  103. bunke_id_4100,
  104. bunke_id_4101,
  105. bunke_id_4170,
  106. bunke_id_4172,
  107. bunke_id_4174,
  108. bunke_id_4191,
  109. bunke_id_4192,
  110. bunke_id_4193,
  111. bunke_id_4273,
  112. bunke_id_4357,
  113. bunke_id_4358,
  114. bunke_id_4359,
  115. bunke_id_4360
  116. )))
  117. PIVOT (SUM(nvl(bunke_count,0)) FOR BRUGERE IN ('legr' AS "legr", 'salu' AS "salu", 'chba' AS "chba", 'jath' AS "jath",'emjo' AS "emjo", 'mama' AS "mama"))) a
  118. LEFT JOIN BUNKER b ON LTRIM(a.BUNKE_ID, 'BUNKE_ID_') = b.BUNKE_ID
  119. --ORDER BY a.BUNKE_ID DESC
  120. )
  121.  
  122. SELECT a.*, b."legr", b."salu", b."chba", b."jath", b."emjo", b."mama" FROM statq1 a
  123. LEFT JOIN statq2 b ON a.BUNKE_ID = b.BUNKE_ID
  124. --ORDER BY a.BUNKENAVN ASC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement