02-29-2008, 02:18 PM
|
#4 (permalink)
|
|
The Wanderer
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
|
I would let mysql do the work for me. But first, I would get my relational data in the database named correctly. Make it like below, so that book_id in your log table relates to book_id in books table, same with user_id... nit picky observation of mine. ;)
Code:
Users
- user_id
Log
- log_id
- user_id
- book_id
Books
- book_id
Now let mysql do the work for you using a query similar to this:
Code:
SELECT user_id,
(COUNT(book_id) FROM books) AS total_books,
(total_books/100)*COUNT(*) AS book_completion_pctg
FROM log
GROUP BY user_id
ORDER BY book_completion_pctg DESC
I haven't tested this, or thought it through much but hopefully that might get you on the right track.
|
|
|