Thursday, February 20, 2014

Sort mysql query



As shown above, how to sort by the highest number of 11,5 appear?
This figure is obviously the first one should be allowed to 11,5,3 discharged<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
select nt.nickname, nt.account, nt.pic, nt.ofusername, nt.tagprimes
from (
select ...
union
select ...
) Nt order by nt.tagprimes desc
Is that OK?

Reply:
No, I'm talking about the number of occurrences of up 11,5
Reply:
Resolved, as
---------------
SELECT u.id, u.nickname, u.pic, u.gender, u.ofusername, readgrade.value, u.doreadbook, book.name, u.profile, u.age, u.tagprimes
FROM app_user u
LEFT JOIN app_source readgrade ON u.readgrade = readgrade.value AND readgrade.stype = 'readgrade'
LEFT JOIN app_book book ON u.doreadbook = book.id
WHERE u.tagprimesum% 2 = 0 OR u.tagprimesum% 3 = 0
ORDER BY IF (u.tagprimesum% 2 = 0,1,0) + IF (u.tagprimesum% 3 = 0,1,0) DESC

No comments:

Post a Comment