Skip to content
Advertisement

How to select middle 80% rows in Oracle SQL with order by (top % is not working)

I tried top % but that is not working in Oracle SQL. Offset and fetch next are working but I am not able to give percentage.

What will be the best way to fetch middle 80% rows?

Any help will be appreciated, thanks!

Advertisement

Answer

Middle 80%? That’s between 10 and 90%, then? Let’s suppose it is.

Sample data (Scott’s EMP table), sorted by salary:

CTE ranks employees by their salaries; the final where clause returns rows for those of them who fall into that “middle” 80% (the pct column).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement