Page 1 of 1

How to calculate the median

Posted: Fri Nov 18, 2016 1:31 pm
by atul.pdm@gmail.com
I need median of the (TIMESTAMPDIFF('ss',submission_time,start_time) in below query.
My query giving the syntax error.please suggest

Code: Select all

SELECT count(job_number),median(TIMESTAMPDIFF('ss',submission_time,start_time)) as median from acctn;

Re: How to calculate the median

Posted: Fri Nov 18, 2016 2:02 pm
by JimKnicely
Hi,

The MEDIAN function in Vertica is an Analytic Function and it requires an OVER() clause.

See:
https://my.vertica.com/docs/8.0.x/HTML/ ... alytic.htm

Something like this might work for you:

Code: Select all

SELECT count(job_number) OVER() as job_number_count,median(TIMESTAMPDIFF('ss',submission_time,start_time)) OVER() as median from acctn LIMIT 1;