关于 order by 子句里面用到 case when 的例子
SELECT * FROM (
SELECT 'a' AS a , 1 AS b FROM dual
UNION ALL
SELECT 'a' AS a , 2 AS b FROM dual
UNION ALL
SELECT 'b' AS a , 2 AS b FROM dual
UNION ALL
SELECT 'b' AS a , 1 AS b FROM dual
) a
ORDER BY (CASE WHEN a.a = 'a' THEN 't' ELSE 'd' END )
+ a.b
这里很奇怪,去掉红色的部分就可以正常运行。
此例应该如何改才能排序出
b,1
b,2
a,1
a,2
1 要求在order by 子句里面用到 case when
2 除了 order by a desc , b 这个答案。
------解决方案--------------------'a'+1 当然报错
+a.b改成
------解决方案--------------------a.b
------解决方案--------------------红色部分的 + 改成 ,