2016-11-20 27 views
0

3つのクエリがあるが、それhrv_empworkingarea表があることを1つのノートビューテーブル3つのクエリから一つのクエリ

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

を(グループなしの合計金額)
このようにして1行で結果を取得することもできます。

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' 
);