在Oracle中按选择查询排序

时间:2016-07-12 06:41:25

标签: sql oracle10g

我想在Order By子句中使用查询,这可能......?

select s.staff_list_pk, s.staff_name, Designation_fn(s.designation_fk) 
Designation, s.bps,  Department_fn(s.department_fk) Department 
from staff_list s
where s.RESERVE = 'N' and s.INTEREST = 'I' 
and s.bps in (18,19,20)
and s.department_fk in (select department_fk from perority_dept 
where `et_blcok = 'Comp. Engg.')
and s.staff_list_pk not in (select staff_list_fk from SUPERINTENDENT) 
order by (select perority from perority_dept where et_blcok = 'Comp. Engg.'), s.bps desc;

1 个答案:

答案 0 :(得分:0)

这应该有效。请尝试一次。

with xyz as  (SELECT department_fk ,perority
                                 FROM perority_dept
                                WHERE et_blcok = 'Comp. Engg.'),

     klm as (select staff_list_fk 
             from SUPERINTENDENT)                         

SELECT s.staff_list_pk,
       s.staff_name,
       Designation_fn (s.designation_fk) Designation,
       s.bps,
       Department_fn (s.department_fk) Department
  FROM staff_list s , xyz x ,klm k
 WHERE     s.RESERVE = 'N'
       AND s.INTEREST = 'I'
       AND s.bps IN (18, 19, 20)
       AND s.department_fk =   x.department_fk                                      
       and s.staff_list_pk <> k.staff_list_fk
      order by xyz.perority,s.bps desc;