sql multiple rows of data into the data row

Target: sql multiple rows of data into the data row

Involving grammar: decode, nvl, left join, subquery.

     --nvl (a, b) -> does not exist if a display b, or display a 
     --decode, Oracle unique if, else; eg: decode ( a, 1,2); if a = 1, it Back to 2
2 the SELECT . 3 A.EMPLOYEE_GID, . 4 A.EVALUATE_YEAR, . 5 the DECODE (of the NVL (A.EVALUATION_STEP, 0), 0, 0,. 1,. 1) the AS STEP1, . 6 the DECODE (of the NVL (B.EVALUATION_STEP, 0), 0 , 0, 2,. 1) the AS STEP2, . 7 the DECODE (of the NVL (C.EVALUATION_STEP, 0), 0, 0,. 3,. 1) the AS STEP3, . 8 (of the NVL (C.EVALUATION_STEP, B.EVALUATION_STEP) . 9 || the DECODE ( of the NVL (A.EVALUATION_STEP, 0), 0, 0,. 1,. 1 ) 10 || the DECODE (of the NVL (B.EVALUATION_STEP, 0), 0, 0, 2,. 1)) COMBINE_STEP the AS, . 11 DECODE((NVL(C.EVALUATION_STEP, B.EVALUATION_STEP) 12 || DECODE(NVL(A.EVALUATION_STEP, 0), 0, 0, 1, 1) 13 || DECODE(NVL(B.EVALUATION_STEP, 0), 0, 0, 2, 1)), 311, 2, 301, 2, 300, 0, 310, 1, 211, 2, 201, 2) AS WITHDRAW_STEP14 , 15 DECODE((NVL(C.EVALUATION_STEP, B.EVALUATION_STEP) 16 || DECODE(NVL(A.EVALUATION_STEP, 0), 0, 0, 1, 1) 17 || DECODE(NVL(B.EVALUATION_STEP, 0), 0, 0, 2, 1)), 311, 1, 301, 0, 300, 0, 310, 0, 211, 1, 201, 0) AS WITHDRAW_COLOR18 FROM 19 ( 20 SELECT 21 * 22 FROM 23 T_EVALUATION A 24 WHERE 25 EVALUATION_STEP = 1 26 ) A 27 LEFT JOIN ( 28 SELECT 29 * 30 FROM 31 T_EVALUATION A 32 WHERE 33 EVALUATION_STEP = 2 34 ) B ON A.EVALUATE_YEAR = B.EVALUATE_YEAR 35 AND A.EMPLOYEE_GID = B.EMPLOYEE_GID 36 LEFT JOIN ( 37 SELECT 38 * 39 FROM 40 T_EVALUATION A 41 WHERE 42 EVALUATION_STEP = 3 43 ) C ON A.EVALUATE_YEAR = C.EVALUATE_YEAR 44 AND A.EMPLOYEE_GID = C.EMPLOYEE_GID 45 WHERE 46 A.EVALUATE_YEAR = ( 47 SELECT 48 VALUE 49 FROM 50 S_SYSTEM_CONFIG 51 WHERE 52 KEY = 'CURRENT_FINANCE_YEAR' 53 AND ENABLE = 1 54 ) 55 AND ( C.EVALUATION_STEP IS NOT NULL 56 OR B.EVALUATION_STEP IS NOT NULL )

 

Guess you like

Origin www.cnblogs.com/xiaoshahai/p/11589771.html