php-db | 2000121
Date: 12/06/00
- Next message: Ian: "[PHP-DB] Problem - Insert data into mysql"
- Previous message: omar cromwell mercado: "[PHP-DB] proper way to save/retrieve a clob data"
- In reply to: Chad Day: "[PHP-DB] auto incrementing rows from query.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Greetings, Chad!
At 06.12.2000, 11:00, you wrote:
CD> I'm trying to determine the percentile value of where a row lies in a
CD> query.. hard to explain, but I'll try.
CD> I do a select all of my table, sorting it by SCORE. I want to find the
CD> position of a certain row in that select all, get that row #, and then I can
CD> calculate the percentile fine by dividing that position into the total # of
CD> rows, then multiplying by 100.
CD> my code is like:
CD> $querysetup = "SELECT SCORE, PID from pictures where VOTES > 100 order by
CD> SCORE DESC";
Ugh. I don't think that I quite get you, but:
If you want to find "that row" by SCORE, then you should issue something like
SELECT COUNT(*) FROM pictures WHERE VOTES>100 AND
SCORE>$your_needed_SCORE
If you want to find "that row" by PID, then
SELECT COUNT(*) FROM pictures WHERE VOTES>100 AND SCORE>(SELECT SCORE
FROM pictures WHERE PID=$your_needed_PID)
Thus you get the number of rows before "that row"
Then issue
SELECT COUNT(*) FROM pictures WHERE VOTES>100
to get _total_ number of rows
then divide one by the other, multiply by 100 and you're all done. :]
I'm almost sure that can be done in a more elegant way, though...
-- Yours, Alexey V. Borzov, Webmaster of RDW-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Ian: "[PHP-DB] Problem - Insert data into mysql"
- Previous message: omar cromwell mercado: "[PHP-DB] proper way to save/retrieve a clob data"
- In reply to: Chad Day: "[PHP-DB] auto incrementing rows from query.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

