从三个查询

时间:2016-11-20 06:41:53

标签: jquery oracle

有三个查询想让它成为hrv_empworkingarea表是视图表

的一个注释
   select count(distinct dept_no) 
      total_dept 
   FROM hrv_empworkingarea  
      where short_name LIKE 'IN'  AND active_flag='Y'; 

   select count(a.doctor_no) 
       total_doctor 
   from   hpms_doctor a  
       where   a.active_flag= 'Y';

   select count(job_id) 
      totalNurse 
   from   HR_EMPLOYEE   
      where   job_id= '155';

2 个答案:

答案 0 :(得分:0)

试试这个:

SELECT COUNT(distinct dept_no) AS total_dept, (
  SELECT COUNT(a.doctor_no)   
   FROM hpms_doctor a  
   WHERE a.active_flag= 'Y'
) AS total_doctor ,
(
  SELECT COUNT(job_id) 
   FROM HR_EMPLOYEE   
   WHERE job_id= '155'
) AS totalNurse 
   FROM hrv_empworkingarea  
   WHERE short_name LIKE 'IN'  AND active_flag='Y'

答案 1 :(得分:0)

事实上这似乎是单一结果(没有分组的总值)
你也可以用这种方式获得单行结果

select 
      max(total_dept) total_dept
    , max(total_doctor) total_doctor
    , max(totalNurse) totalNurse
from (
   select count(distinct dept_no) total_dept, null  total_doctor, null totalNurse
   FROM hrv_empworkingarea  
      where short_name LIKE 'IN'  AND active_flag='Y'; 
   UNION ALL
   select null, count(a.doctor_no), null 
       total_doctor 
   from   hpms_doctor a  
       where   a.active_flag= 'Y';
   UNION ALL 
   select null, null, count(job_id) 
      totalNurse 
   from   HR_EMPLOYEE   
      where   job_id= '155'
);