gjc
gjc

Reputation: 39

PostgreSQL want to round percentile_cont

I am computing a range of values in PostgreSQL, and I want to round some of them to 2 decimal places. when I do round the average it works round(avg(rate), 2) as avg_rate. when I round the median round(percentile_cont(0.5) within group (order by rate) as med, it gives an error saying I need to add explicit type casts. the percentile_cont works fine without the round, but I am unsure how to fix this. any help would be appreciated. thanks

Upvotes: 1

Views: 669

Answers (1)

LukStorms
LukStorms

Reputation: 29647

Type casting it to decimal will also round the median

percentile_cont(0.5) within group (order by rate)::decimal(8,2) as median

Upvotes: 2

Related Questions