I try to avoid using databases, or even PHP, as much as possible, but if I have to, I use SQLite. From table 'data', column names book,id,units,amount this does what you seem to want:
select book,id,sum(units),sum(amount) from data group by book order by sum(amount) ASC;
MySQL is probably similar.
__________________
__________________
|