嗨我有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列.... –