depends on how loaded the database is...
if it is heavily loaded, just get the values, and do the processing and sorting in php (you really should never have to do it if you set up the database right and know how to write complicated queries)
if it is barely used, go nutty and make 20 temp tables, because then you don't have to worry about writing the sorting algorithms.