php - MySql different order by conditions -


i have mysql query

select `adddate`, `pexpdate`, `level` `localhost-tests` 1 order `level` desc, `pexpdate` desc, `adddate` desc 

returns me

mysql query result

problem is, if part levels > 0 fine, , sorted pexpdate, second part, level = 0, must sorted adddate, not pexpdate.

i've tried:

where 1 order order `level` desc, `pexpdate` desc, `adddate` desc 1 order if(`level`, `pexpdate`, `adddate`) desc 1 order level desc, ifnull(pexpdate, adddate) desc limit 5 

question: how sort part of result level = 0 adddate.

first of all, where 1 part useless. don't need where specify order clause.

then, use union.

select `adddate`, `pexpdate`, `level` `localhost-tests` `level` <> 0 order `level` desc, `pexpdate` desc, `adddate` desc union select `adddate`, `pexpdate`, `level` `localhost-tests` `level` = 0 order `adddate` desc 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -