0

我有一个查询

select username,amount from employee
union all
select '' as username,sum(amount) from employee
order by cast(username as decimal)

用户名从 1000 开始

当我使用此查询时,它始终显示从最高用户名到最小用户名

我想将最小的用户名显示到最高的用户名

我为此做什么?

4

1 回答 1

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
于 2012-10-22T08:42:02.583 回答