Further to a recently answered question, I have the following code:
SELECT q21coding, COUNT(q21coding) AS Count
FROM tresults_acme
WHERE q21 IS NOT NULL AND q21 <> ''
GROUP BY q21coding
ORDER BY IF(q21coding = 'Other', 1, 0) ASC, Count DESC
It brings back the following:
q21coding Count
Difficulty in navigating/finding content 53
Positive comments 28
Suggestions for improvement 14
Inappropriate content/use 13
Improve search facility 6
Include information about staff and teams 5
Content needs updating 4
Other 30
You’ll notice that Other is now at the bottom – However is there a way of ensuring that Positive comments and Other is ALWAYS the bottom two (with other at the bottom) regardless of the Count size?
Thanks,
Homer
Actually there was no need to use
IF(q21coding = 'Other', 1, 0)in your original query. In MySQL you can use any expression in theORDER BYcaluse andq21coding = 'Other'would have been enough:The
q21coding = 'Other'expression will return1if true, or0if false. That will put rows with aq21coding = 'Other'at the bottom.What you need to do to have ‘Positive Comments’ and ‘Other’ both at the bottom is something like this:
Basic test case:
Result: