Cumulative count cut with postgresql -
is there possibility realize cumulative count cut of 2.0 - 98.0% in postgresql?
that means select data range set 2% until 98%.
i suggest window function ntile()
in subquery:
select * ( select *, ntile(50) on (order ts) part tbl ts >= $start , ts < $end ) sub part not in (1, 50);
ts
being date
column.
ntile()
assigns integer numbers rows dividing them number of partitions specified. per documentation:
integer ranging 1 argument value, dividing partition equally possible
by using 50 partitions first partition matches first 2 % closely possible , last last 2 % (> 98%).
note, if there less 50 rows assigned numbers never go 50. in case first row trimmed not last. since first , last 2 % not defined such low number of rows may considered correct or incorrect. check total number of rows , adapt needs. instance trimming last row, too. or none @ all.
Comments
Post a Comment