SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with t as ( select row_number() over(order by total_amount) as n, count(1) over() as cnt, total_amount from bookings where book_date between '2017-07-01' and '2017-07-31 23:59:59' ) select avg(total_amount) as median_amount from t where n = cnt / 2 or n = cnt / 2 + 1 ; select * from query_cost('with t as ( select row_number() over(order by total_amount) as n, count(1) over() as cnt, total_amount from bookings where book_date between ''2017-07-01'' and ''2017-07-31 23:59:59'' ) select avg(total_amount) as median_amount from t where n = cnt / 2 or n = cnt / 2 + 1 ');

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear