1. SQL / Говнокод #20393

    +12

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    SELECT
    real_day, 1 start_mon, TO_NUMBER(TO_CHAR(LAST_DAY(TO_DATE ('{date}','dd.mm.yyyy')),'dd')) end_mon,
    (CASE WHEN d.t1_aup_f IS NULL THEN (
      CASE WHEN (lag(sum(d.t1_aup_f),1) over (order by d.real_day)) IS NULL THEN (
       CASE WHEN (lag(sum(d.t1_aup_f),2) over (order by d.real_day)) IS NULL THEN (
        CASE WHEN (lag(sum(d.t1_aup_f),3) over (order by d.real_day)) IS NULL THEN (
         CASE WHEN (lag(sum(d.t1_aup_f),4) over (order by d.real_day)) IS NULL THEN (
          CASE WHEN (lag(sum(d.t1_aup_f),5) over (order by d.real_day)) IS NULL THEN (
           CASE WHEN (lag(sum(d.t1_aup_f),6) over (order by d.real_day)) IS NULL THEN (
            CASE WHEN (lag(sum(d.t1_aup_f),7) over (order by d.real_day)) IS NULL THEN (
             CASE WHEN (lag(sum(d.t1_aup_f),8) over (order by d.real_day)) IS NULL THEN (
              CASE WHEN (lag(sum(d.t1_aup_f),9) over (order by d.real_day)) IS NULL THEN (
               CASE WHEN (lag(sum(d.t1_aup_f),10) over (order by d.real_day)) IS NULL THEN (
                CASE WHEN (lag(sum(d.t1_aup_f),11) over (order by d.real_day)) IS NULL THEN (
                 CASE WHEN (lag(sum(d.t1_aup_f),12) over (order by d.real_day)) IS NULL THEN (
                  CASE WHEN (lag(sum(d.t1_aup_f),13) over (order by d.real_day)) IS NULL THEN (
                   CASE WHEN (lag(sum(d.t1_aup_f),14) over (order by d.real_day)) IS NULL THEN (
                    CASE WHEN (lag(sum(d.t1_aup_f),15) over (order by d.real_day)) IS NULL THEN (
                     CASE WHEN (lag(sum(d.t1_aup_f),16) over (order by d.real_day)) IS NULL THEN (
                      CASE WHEN (lag(sum(d.t1_aup_f),17) over (order by d.real_day)) IS NULL THEN (
                       CASE WHEN (lag(sum(d.t1_aup_f),18) over (order by d.real_day)) IS NULL THEN (
                        CASE WHEN (lag(sum(d.t1_aup_f),19) over (order by d.real_day)) IS NULL THEN (
                         CASE WHEN (lag(sum(d.t1_aup_f),20) over (order by d.real_day)) IS NULL THEN (
                          CASE WHEN (lag(sum(d.t1_aup_f),21) over (order by d.real_day)) IS NULL THEN (
                           CASE WHEN (lag(sum(d.t1_aup_f),22) over (order by d.real_day)) IS NULL THEN (
                            CASE WHEN (lag(sum(d.t1_aup_f),23) over (order by d.real_day)) IS NULL THEN (
                             CASE WHEN (lag(sum(d.t1_aup_f),24) over (order by d.real_day)) IS NULL THEN (
                              CASE WHEN (lag(sum(d.t1_aup_f),25) over (order by d.real_day)) IS NULL THEN (
                               CASE WHEN (lag(sum(d.t1_aup_f),26) over (order by d.real_day)) IS NULL THEN (
                                CASE WHEN (lag(sum(d.t1_aup_f),27) over (order by d.real_day)) IS NULL THEN (
                                 CASE WHEN (lag(sum(d.t1_aup_f),28) over (order by d.real_day)) IS NULL THEN (
                                  CASE WHEN (lag(sum(d.t1_aup_f),29) over (order by d.real_day)) IS NULL THEN
                                   lag(sum(d.t1_aup_f),30) over (order by d.real_day )
                                  ELSE (lag(sum(d.t1_aup_f),29) over (order by d.real_day)) END)
                                 ELSE (lag(sum(d.t1_aup_f),28) over (order by d.real_day)) END)
                                ELSE (lag(sum(d.t1_aup_f),27) over (order by d.real_day)) END)
                               ELSE (lag(sum(d.t1_aup_f),26) over (order by d.real_day)) END)
                              ELSE (lag(sum(d.t1_aup_f),25) over (order by d.real_day)) END)
                             ELSE (lag(sum(d.t1_aup_f),24) over (order by d.real_day)) END)
                            ELSE (lag(sum(d.t1_aup_f),23) over (order by d.real_day)) END)
                           ELSE (lag(sum(d.t1_aup_f),22) over (order by d.real_day)) END)
                          ELSE (lag(sum(d.t1_aup_f),21) over (order by d.real_day)) END)
                         ELSE (lag(sum(d.t1_aup_f),20) over (order by d.real_day)) END)
                        ELSE (lag(sum(d.t1_aup_f),19) over (order by d.real_day)) END)
                       ELSE (lag(sum(d.t1_aup_f),18) over (order by d.real_day)) END)
                      ELSE (lag(sum(d.t1_aup_f),17) over (order by d.real_day)) END)
                     ELSE (lag(sum(d.t1_aup_f),16) over (order by d.real_day)) END)
                    ELSE (lag(sum(d.t1_aup_f),15) over (order by d.real_day)) END)
                   ELSE (lag(sum(d.t1_aup_f),14) over (order by d.real_day)) END)
                  ELSE (lag(sum(d.t1_aup_f),13) over (order by d.real_day)) END)
                 ELSE (lag(sum(d.t1_aup_f),12) over (order by d.real_day)) END)
                ELSE (lag(sum(d.t1_aup_f),11) over (order by d.real_day)) END)
               ELSE (lag(sum(d.t1_aup_f),10) over (order by d.real_day)) END)
              ELSE (lag(sum(d.t1_aup_f),9) over (order by d.real_day)) END)
             ELSE (lag(sum(d.t1_aup_f),8) over (order by d.real_day)) END)
            ELSE (lag(sum(d.t1_aup_f),7) over (order by d.real_day)) END)
           ELSE (lag(sum(d.t1_aup_f),6) over (order by d.real_day)) END)
          ELSE (lag(sum(d.t1_aup_f),5) over (order by d.real_day)) END)
         ELSE (lag(sum(d.t1_aup_f),4) over (order by d.real_day)) END)
        ELSE (lag(sum(d.t1_aup_f),3) over (order by d.real_day)) END)
       ELSE (lag(sum(d.t1_aup_f),2) over (order by d.real_day)) END)
      ELSE (lag(sum(d.t1_aup_f),1) over (order by d.real_day)) END)
    ELSE d.t1_aup_f END) gf_1,
    ........

    Фул: http://paste.org.ru/?zlc3b8
    via https://habrahabr.ru/post/305926/#comment_9706606

    Запостил: package, 19 Июля 2016

    Комментарии (9) RSS

    Добавить комментарий