我有一个查询,它是另外3个comples查询的联合。有些事情如下
SELECT 'type_one' as typename, typeid, typetitle from abc, def
UNION
SELECT 'type_two' as typename, typeid, typetitle from xyz, pqr
UNION
SELECT 'type_three' as typename, typeid, typetitle from mno, ijk
order by date desc
以上查询说返回15条记录,按日期desc排序。我想用' type_two'来获取记录。并且最近的日期始终为第一行(可能有多行' type_two'),然后获取按日期desc排序的其余记录。任何人都可以指出在Oracle中这样做的方法吗?谢谢
答案 0 :(得分:1)
使用CASE为所需列赋予不同的权重
SELECT 'type_one' as typename, typeid, typetitle from abc, def
UNION
SELECT 'type_two' as typename, typeid, typetitle from xyz, pqr
UNION
SELECT 'type_three' as typename, typeid, typetitle from mno, ijk
order by CASE WHEN typename='type_two' THEN 0 ELSE 1 END,date desc