我需要按列字段的升序在结果集的最后放置一条记录。
比如:
SELECT "#TOTAL"...
它是用户定义的列值。
我想做的是:
SELECT cnt.name as Client, NULL, NULL, NULL, ', @COL_SUM, '
FROM
task as tsk
LEFT JOIN client cnt
ON tsk.client_id = cnt.id
GROUP BY tsk.client_id
UNION ALL
SELECT "#TOTAL#",NULL,NULL,NULL, ', @COL_SUM, '
FROM task as tsk
ORDER BY Client ASC
这将结果集返回为:
Client | ... | Admin | Intern | ..
---------------------------------------
#TOTAL# | ... | 4 | 2 | .. <-- this row here is grand total
A | ... | 1 | | ..
B | ... | 1 | 1 | ..
C | ... | 2 | 1 | ..
我希望
#TOTAL#
行最后结束。除了
z
,什么字符最后是按字母顺序排列的? 最佳答案
只需将您的条件添加到ORDER BY
子句中:
order by Client = '#TOTAL#', Client
关于mysql - 按字母顺序sql排在最后的特殊字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57161114/