DB/SQL
-
SQL - String To SplitDB/SQL 2023. 8. 7. 15:04
문자열과 구분자를 받아서 Split 하는 Function Split 이후 IN 조건으로 활용 -- 변수부터 진행 CREATE OR REPLACE TYPE ESHOP.T_VARCHAR2 AS TABLE OF VARCHAR2(32767); -- FUNC 생성 CREATE OR REPLACE FUNCTION ESHOP.F_STRING_TO_SPLIT ( P_STR IN VARCHAR2, P_SEP IN VARCHAR2 DEFAULT ',' ) RETURN T_VARCHAR2 IS L_RESULT T_VARCHAR2 := T_VARCHAR2(); L_STR_LENGTH PLS_INTEGER; L_SEP_LENGTH PLS_INTEGER; L_SEP_TYPE BOOLEAN; L_START PLS_INTEGER N..
-
SQL Study3 - SELECTDB/SQL 2018. 8. 7. 09:40
-- 46. 사원수가 가장 많은 도시에서 근무하는 모든 사원들의 부서별 및-- 직무별 평균 연봉을 조회하라.SELECT L.CITY , D.DEPARTMENT_NAME , J.JOB_ID , ROUND(AVG(E.SALARY) , 0) AVG_SALARYFROM EMPLOYEES E , DEPARTMENTS D , LOCATIONS L , JOBS J , ( SELECT * FROM ( SELECT L.CITY , COUNT(1) CNT FROM EMPLOYEES E , DEPARTMENTS D , LOCATIONS L WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID AND D.LOCATION_ID = L.LOCATION_ID GROUP BY L.CITY ORDER BY CNT D..
-
SQL Study2 - SELECTDB/SQL 2018. 8. 6. 14:54
-- 1. 모든 사원의 이름(FIRST_NAME, LAST_NAME)을 조회하라. SELECT FIRST_NAME , LAST_NAMEFROM EMPLOYEES; -- 2. 모든 사원의 모든 정보를 조회하라.SELECT *FROM EMPLOYEES; -- 3. 모든 도시 명을 조회하라.SELECT CITYFROM LOCATIONS; -- 4. 이름(FIRST_NAME)이 M 으로 시작하는 사원의 모든 정보를 조회하라.SELECT *FROM EMPLOYEESWHERE FIRST_NAME LIKE 'M%'; -- 5. 이름(FIRST_NAME)의 두 번째 글자가 'a'인 사원의 이름(FIRST_NAME)과 연봉을 조회하라.SELECT FIRST_NAME , SALARYFROM EMPLOYEESWHERE FI..
-
SQL SELECT StudyDB/SQL 2018. 8. 3. 17:39
-- 5. 이름(FIRST_NAME)의 두 번째 글자가 'a'인 사원의 이름(FIRST_NAME)과 연봉을 조회하라.SELECT FIRST_NAME, SALARYFROM EMPLOYEESWHERE FIRST_NAME LIKE '_a%'; -- 21. 모든 사원들의 사원번호, 부서명, 직무명, 도시명을 조회하라.SELECT E.EMPLOYEE_ID, D.DEPARTMENT_NAME, J.JOB_ID, L.CITYFROM DEPARTMENTS D , LOCATIONS L , EMPLOYEES E , JOBS JWHERE E.DEPARTMENT_ID = D.DEPARTMENT_IDAND D.LOCATION_ID = L.LOCATION_IDAND J.JOB_ID = E.JOB_ID; -- 37. 자신의 상사가 ..
-
SQL - JOIN, SUB QUERY, INLINE TABLE, IN VIEWDB/SQL 2018. 8. 3. 16:36
SELECT *FROM EMPLOYEESWHERE DEPARTMENT_ID IN ( SELECT DEPARTMENT_ID FROM EMPLOYEES WHERE FIRST_NAME = 'Steven' )AND FIRST_NAME != 'Steven' -- 여러개일때는 IN 사용; SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.SALARY, D.DEPARTMENT_NAMEFROM EMPLOYEES E, DEPARTMENTS DWHERE SALARY > ( SELECT ROUND( AVG(SALARY), 0 ) FROM EMPLOYEES )ORDER BY SALARY; SELECT E.*FROM DEPARTMENTS D , LOCATIONS L , EMPLOYEES..
-
SQL - SELECTDB/SQL 2018. 8. 1. 17:24
SELECT FIRST_NAME , LAST_NAMEFROM EMPLOYEES; SELECT *FROM EMPLOYEES; SELECT CITYFROM LOCATIONS; SELECT DEPARTMENT_NAMEFROM DEPARTMENTS; SELECT COUNTRY_ID , COUNTRY_NAMEFROM COUNTRIES; SELECT DISTINCT MANAGER_ID , FIRST_NAMEFROM EMPLOYEESORDER BY MANAGER_ID DESC; SELECT *FROM EMPLOYEESORDER BY EMPLOYEE_ID ASC; SELECT *FROM EMPLOYEESORDER BY SALARY DESC; SELECT *FROM EMPLOYEESORDER BY HIRE_DATE AS..