조건에 따른 COUNT를 멋지게 할 수 있는 방법을 고민하며,
CASE WHEN THEN~ , OVER(PARTITON BY) 말고는 뭐가 있을까 하다가
PL/SQL 에 손대보기로 하였다.
show global variables like 'log_bin_trust_function_creators';
SET GLOBAL log_bin_trust_function_creators = 1;
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled
DROP FUNCTION IF EXISTS get_result_count;
CREATE FUNCTION get_result_count(e_id NUMBER,e_name VARCHAR(20),d_type VARCHAR(20)) RETURNS NUMBER
-- EMPLOYEES.FIRST_NAME%TYPE
BEGIN
DECLARE r_count INT;
SELECT count(*)
INTO r_count
FROM oms_ob_call_results
WHERE EMPLOYEE_ID = e_id AND FIRST_NAME = e_name AND DEPARTMENT_ID = d_type;
RETURN r_count;
END;
SELECT EMPLOYEE_ID, FIRST_NAME, get_result_count(EMPLOYEE_ID, FIRST_NAME, 'SALES') as sales_number, get_result_count(strategy_id, call_list_id, 'MARKETING') as marketing_number
FROM EMPLOYEE;