2016-11-20 49 views
0

有三个查询想让它一个需要注意的是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'; 

回答

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' 
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' 
); 
获得在单排的结果