id | name | good_name | payment |
1 | a | aa | true |
2 | b | bb | payment |
3 | c | cc | true |
(SELECT * FROM `table` WHERE `payment`="true" ORDER BY `good_name` ASC )<br/>
union<br/>
(SELECT * FROM `table` WHERE `payment`="false" ORDER BY `name` ASC )<br/>
SELECT
*,
IF(`payment`='true', `good_name`, `name`) prior
FROM `table`
WHERE
`payment`="true"
ORDER BY payment, prior
SELECT * FROM (
SELECT * FROM `table` WHERE `payment`=="true" ORDER BY `good_name` ASC
) a
UNION
select * from (
SELECT * FROM `table` WHERE `payment`=="false" ORDER BY `name` ASC
) b
SELECT id, name, good_name, payment
FROM (SELECT TOP (100) PERCENT id, name, good_name, payment, good_name AS ordr
FROM temp
WHERE (payment = 1)
UNION
SELECT TOP (100) PERCENT id, name, good_name, payment, name AS ordr
FROM temp AS temp_1
WHERE (payment = 0)) AS t2_1
ORDER BY payment DESC, ordr
* This source code was highlighted with Source Code Highlighter.