SELECT DISTINCT t1.scd_evaluation_id , t1.scd_evaluator_id , ( CASE WHEN t1.assgn_cnt =1 THEN t3.scd_section_id WHEN t1.assgn_cnt=t2.bld_Sect_Cnt THEN 'All' ELSE 'Multiple' END) AS scd_section_id , ( CASE WHEN t1.assgn_cnt =1 THEN t2.scd_section_name WHEN t1.assgn_cnt=t2.bld_Sect_Cnt THEN 'All' ELSE 'Multiple' END) AS scd_section_name , t1.assgn_cnt , t2.bld_Sect_Cnt FROM ( SELECT us.scd_evaluation_id , us.scd_evaluator_id , COUNT(1) assgn_cnt , 0 unassgn_cnt FROM ps_scd_usreval_sct us WHERE us.select_flag = 'Y' GROUP BY us.scd_evaluation_id, us.scd_evaluator_id ) t1 INNER JOIN ( SELECT bs.scd_evaluation_id , bs.scd_section_name , bs.SCD_BLD_SECT_CNT bld_Sect_Cnt FROM PS_SCD_EVA_SECN_VW bs) t2 ON t1.scd_evaluation_id=t2.scd_evaluation_id INNER JOIN ps_scd_usreval_sct t3 ON t1.scd_evaluation_id=t3.scd_evaluation_id AND t1.scd_evaluator_id=t3.scd_evaluator_id AND t3.select_flag='Y'
|