Wpis z mikrobloga

#sql #bazydanych
Jak zmusić #postgresql, żeby uwzględniał nulle przy liczeniu percentyli?
Gdyby uwzględniał, to wyniki tych dwóch kwerend byłyby różne, bo nulle wstawione na górę lub dół popchnęłyby inne wartości na środek.

changesets=# select percentile_disc(0.5) within group (order by age nulls last ) from (select closed_at - created_at as age from note a, boundaries b where ST_Intersects(a.geom,b.geom) ) s;
percentile_disc
------------------
11 days 05:01:46
(1 row)
changesets=# select percentile_disc(0.5) within group (order by age nulls first ) from (select closed_at - created_at as age from note a, boundaries b where ST_Intersects(a.geom,b.geom) ) s;
percentile_disc
------------------
11 days 05:01:46
(1 row)
  • 6
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach

@ck__: Jest to myśl. Chyba działa OK. Dzięki ( ͡° ͜ʖ ͡°)

changesets=# select percentile_disc(0.5) within group (order by age ) from (select coalesce( closed_at - created_at, '99999 days'::interval) as age from note a, boundaries b where ST_Intersects(a.geom,b.geom) )
  • Odpowiedz