As the subject line says, I'm a bit new at this databasing stuff, and I'm not quite sure how best to structure a particular query I need to do.
The structure of the relevant portion of the records I want to work with is as follows:
An integer "flag", which can equal 0 or 1.
An integer "total0", which can have any positive value.
An integer "total1", which can have any positive value.
I want my result set to contain ten values in descending order of a calculated value we'll call "percent", where:
percent = total0 / (total0 + total1) if flag == 0
percent = total1 / (total0 + total1) if flag == 1
How would I go about writing this query in MySQL 4.0.15?