Nth Select
От | Mark Mitchell |
---|---|
Тема | Nth Select |
Дата | |
Msg-id | 1045786757.22003.0.camel@sql.icnfull.com обсуждение исходный текст |
Список | pgsql-sql |
I'm currently doing an Nth select to filter records as they come back from the database. The Nth works like this, A query is built that returns 2000 results but the user only wants to see 500. To give each row a fair chance we cannot simply use LIMIT 500 instead we get a value for each row by dividing the the number of rows we want to see by number of row returned. So - 500 / 2000 is .25 Now as we return the results we count the value of each row until its greater than or equal to 1. The counter is then reset and the counting continues. Row 1 - Counter is .25 Row 2 - Counter is .50 Row 3 - Counter is .75 Row 4 - Counter is 1 we keep this row and reset the counter. Row 5 - Counter is .25 and so on. Is there any way this can be done by the database before the results are returned to my program? Thanks for any help or pointers. - Mark
В списке pgsql-sql по дате отправления: