嗨我有DB2中正在工作的SQL语句。ORDER BY CASE不起作用?
select distinct 'IN' as STATUS,
(select count(*) from table.......)
from table
UNION ALL
select distinct 'OUT',
(select count(*) from table.......)
from table
UNION ALL
select distinct 'FINISHED',
(select count(*) from table.......)
from table
order by status
但是,如果我的最后一行改为
order by
case STATUS
when 'IN' then 1
when 'OUT' then 2
when 'FINISHED' then 3
end
我的查询不起作用。 有人可以告诉我如何解决这个问题吗? 感谢
什么是错误?记住ORDER BY 1意味着第一列的顺序,并且您只有2列.... –