-
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 ASC;SELECT *FROM EMPLOYEESORDER BY HIRE_DATE, SALARY DESC;SELECT FIRST_NAMEFROM EMPLOYEESORDER BY FIRST_NAME;SELECT *FROM EMPLOYEESWHERE SALARY = 24000AND EMPLOYEE_ID = 100;SELECT *FROM EMPLOYEESWHERE FIRST_NAME = 'Steven'AND SALARY = 2200;SELECT *FROM EMPLOYEESWHERE DEPARTMENT_ID IN 100ORDER BY EMPLOYEE_ID;SELECT *FROM EMPLOYEESWHERE DEPARTMENT_ID IN (60, 90, 100)ORDER BY EMPLOYEE_ID;SELECT *FROM EMPLOYEESWHERE DEPARTMENT_ID NOT IN (60, 90, 100)ORDER BY EMPLOYEE_ID;SELECT *FROM LOCATIONSWHERE COUNTRY_ID IN JP;SELECT *FROM LOCATIONSWHERE COUNTRY_ID IN (JP, CA);SELECT *FROM EMPLOYEESWHERE DEPARTMENT_ID IN (60, 90, 100)AND JOB_ID = 'IT_PROG' -- 값을 하나만 가질때는 = 쓰는게 좋다(연산처리), 문자는 ' 'ORDER BY EMPLOYEE_ID;SELECT *FROM EMPLOYEESWHERE MANAGER_ID IS NULL;SELECT *FROM EMPLOYEESWHERE MANAGER_ID IS NOT NULL;SELECT CITYFROM LOCATIONSWHERE STATE_PROVINCE IS NULLORDER BY CITY DESC;SELECT CITYFROM LOCATIONSWHERE COUNTRY_ID IN ('JP', 'US', 'CA', 'UK')AND STATE_PROVINCE IS NOT NULLORDER BY COUNTRY_ID ASC, CITY DESC;SELECT *FROM EMPLOYEESWHERE FIRST_NAME LIKE 'S%'AND lAST_NAME LIKE 'S%';SELECT *FROM EMPLOYEESWHERE FIRST_NAME LIKE '%ev%'OR LAST_NAME LIKE '%ev%';SELECT FIRST_NAME || ' ' || LAST_NAME NAMEFROM EMPLOYEES;SELECT FIRST_NAME || ' ' || LAST_NAME "이름"FROM EMPLOYEES;SELECT SALARY / 12 MONTHLY_PAYFROM EMPLOYEES;SELECT ROUND(SALARY / 12, 0) MONTHLY_PAYFROM EMPLOYEES;SELECT EMPLOYEE_ID, ROUND (SALARY + (SALARY * COMMISSION_PCT)) SALARYFROM EMPLOYEESWHERE COMMISSION_PCT IS NOT NULL;-- 현재 시간 출력하기SELECT SYSDATEFROM DUAL -- DUMMY TABLE;SELECT *FROM DUAL;SELECT HIRE_DATEFROM EMPLOYEESWHERE HIRE_DATE = '2003/06/17' -- 성능에 문제;SELECT HIRE_DATEFROM EMPLOYEESWHERE HIRE_DATE = TO_DATE('2003/06/17') -- 문자를 날짜로 바꿈;SELECT TO_CHAR(SYSDATE, 'YYYY. MM. DD. HH24:MI:SS') -- 2018-08-01 HH24는 24시간기반FROM DUAL;SELECT TO_DATE(SYSDATE, 'YYYY-MM-DD 00:00:00') -- 날짜 검색때 많이 쓰임FROM DUAL;SELECT *FROM DUAL;SELECT FIRST_NAME || ' ' || LAST_NAME NAME, CASEWHEN COMMISSION_PCT IS NOT NULL THENSALARY + SALARY * COMMISSION_PCTELSESALARYEND SALARY, TO_CHAR(HIRE_DATE, 'YYYY. MM. DD. ') HIRE_DATEFROM EMPLOYEES;반응형
'DB > SQL' 카테고리의 다른 글
Eclipse - SQL Explorer 실행 (0) 2018.08.26 SQL Study3 - SELECT (0) 2018.08.07 SQL Study2 - SELECT (0) 2018.08.06 SQL SELECT Study (0) 2018.08.03 SQL - JOIN, SUB QUERY, INLINE TABLE, IN VIEW (0) 2018.08.03 댓글