SQL Performance (MOSC)

MOSC Banner

HowTo calculate percentile (0.5) (known as median) with windowing clause

edited Feb 10, 2015 9:57AM in SQL Performance (MOSC) 11 commentsAnswered

Hallo,

i have a list of values of i.e. pH-values or temperature values taken on different date (time, day) in DD.MM.YY format, i.E

01.01.2014: pH 4

03.01.2014: ph 5

01.02.2014: ph 5

03.05.2015: ph 6

03.01.2015: ph 7

05.01.2015: ph 7

I have to calculate the median (percentile_cont(0.5)) within a timewindow of 1 year, i.E:

01.01.2014: pH 4: median 4

03.01.2014: ph 5: median 4.5

01.02.2014: ph 5: median 5

03.05.2014: ph 6: median 5

03.01.2015: ph 7: median 6 !! Values from 01.02.2014, 03.05.2014 and 03.01.2015

05.01.2015: ph 7: median 7 !! Values from 03.05.2014, 03.01.2015 and 05.01.2015

So it is percentile calculation within a time window. I was able to calculate it with trivial SQL using subselects within the select part of the main query, but it was to slow.

I have to select from a large table with many rows and many values for each ph-value within a year. So I have to decide whether to use a) pre-calculated median values using trigger technology, b) using materialized views or c) using analytic function.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center