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

    −860

    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
    select 
    (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),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),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 
    from sometable

    таких полей было больше. тут http://paste.org.ru/?zlc3b8 - целиком. для полноты картины. надеюсь, не я написал, хотя... ))))

    Запостил: RomaShka, 15 Апреля 2011

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

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