postgresql - Selecting only the values that are in the 75th percent tile and are above a constraint -


i'm trying query work properly...

select  salary agent salary > 75000 order salary asc limit (select round(count(salary) * .75) twentyfifthtile agent) 

some addition information rows:

  • 166 rows – 25%
  • 331 rows – 50%
  • 497 rows – 75%
  • 662 rows – 100%

these rows have salary 75,000 plus:

235 / 662 = ~.35
.35 * 662 = ~235 rows.

i'm trying above query return rows have salary greater 75,000 still in first 497 rows. when run above query returns rows starting @ 75,000 , limited 497 row return constraint.

i'm not sure how can return salaries of greater 75,000 in first 497 rows of limit constraint.

you can divide total number of rows current row number this:

select salary (   select salary,          count(*) on () total_count,          row_number() on (order salary) rn   agent   salary > 75000 ) t (rn / total_count::numeric) <= 0.75 order salary asc 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -