I am currently trying to optimize a few queries and scripts, and I wonder if there is a way to cut off a certain percentage of a MySQL Result Set?
for example, I have a Query like this:
SELECT TrackingID, OpenTime, FirstPoint
FROM PointsTable
I need the "middle" 74%, ordered by the difference between FirstPointGMT and OpenTimeGMT, which means: I need to cut off the top and bottom 13%.
At the moment, a Script will just get all Rows, calculate and order by duration and then cut them off, but I'd like to do it in an SQL Query if possible to make the script clearer.
I know about the LIMIT Clause, but that does not seem to support relative values like "13 percent".
Can anyone tell if a) if that is actually possible only with SQL and b) how it could be achieved?
MySQL is 5.0.45.
PS: And yes, I know that 13% seems like a very strange number, but that's all part of a bigger process.