我有一个查询
select username,amount from employee
union all
select '' as username,sum(amount) from employee
order by cast(username as decimal)
用户名从1000开始
当我使用此查询时,它始终显示最小用户名
的最高用户名我想将最小的用户名显示为最高用户名
我为此做了什么?
答案 0 :(得分:1)
通过包装在子查询中来尝试它,
SELECT *
FROM
(
SELECT username, amount from employee
UNION ALL
SELECT '' as username, sum(amount) from employee
) x
ORDER BY (CASE WHEN username = '' THEN 1 ELSE 0 END) ASC,
CAST(username AS SIGNED) ASC