Programmers/SQL(34)
-
[mysql/oracle] 흉부외과 또는 일반외과 의사 목록 출력하기
문제 결과 mysql 1 2 3 4 SELECT dr_name, dr_id, mcdp_cd, date_format(hire_ymd, '%Y-%m-%d') hire_ymd from doctor where mcdp_cd = 'CS' or mcdp_cd = 'GS' order by hire_ymd desc, dr_name Colored by Color Scripter cs mysql에서의 날짜 : date_format 2023.01.20 - [DB] - [mysql/oracle] 날짜 형식 : DATE_FORMAT() / TO_CHAR [mysql/oracle] 날짜 형식 : DATE_FORMAT() / TO_CHAR 날짜 형식을 가져오고 싶을 때 TO_CHAR()를 많이 사용한다. 그러나 이 함수는 orac..
2023.01.28 -
[mysql/oracle] 12세 이하인 여자 환자 목록 출력하기
문제 결과 mysql 1 2 3 4 SELECT pt_name, pt_no, gend_cd, age, IFNULL(tlno, 'NONE') TLNO from patient where age
2023.01.28 -
[mysql/oracle] 나이 정보가 없는 회원 수 구하기
문제 결과 mysql 1 2 select sum(age is null) users from user_info cs age가 null이라면 true라서 0을 반환 / null이 아니라면 false라서 1을 반환 oracle 1) decode 1 2 SELECT count(decode(age, null, 0)) users from user_info cs 200개의 row를 decode로 돌리면 200개 중 decode의 조건식에 해당되는 row들만 출력대상이고 조건식에 해당되지 않으면 출력되지 않는다. -> 200개 이하의 row가 출력된다. 그러므로 age가 null인 것들만 count하고 null이 아닌 값들은 출력 대상에서 제외되므로 count 되지 않는다. 2) nvl - 틀린 이유 1 2 SELEC..
2023.01.27 -
[mysql/oracle] NULL 처리하기
문제 결과 mysql / oracle 1. case문 1 2 3 4 5 6 SELECT animal_type, (case when name is null then 'No name' else name end ) name, sex_upon_intake from animal_ins order by animal_id Colored by Color Scripter cs 2. coalesce 1 2 3 SELECT animal_type, coalesce(name, 'No name') name, sex_upon_intake from animal_ins order by animal_id Colored by Color Scripter cs mysql 1. ifnull 1 2 3 SELECT animal_type, ifn..
2023.01.27 -
[mysql/oracle]이름이 있는 동물의 아이디
문제 결과 코드(MYSQL / ORACLE) 1 2 3 4 SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NOT NULL ORDER BY ANIMAL_ID cs where문에 is not null을 쓸 수 있는지 물어보는 문제
2023.01.26 -
[mysql/oracle]경기도에 위치한 식품창고 목록 출력하기
문제 결과 like로 주소가 경기도로 시작하는 row를 출력해주면 된다 1) mysql 1 2 3 4 SELECT WAREHOUSE_ID, WAREHOUSE_NAME, ADDRESS, IFNULL(FREEZER_YN,'N') FREEZER_YN FROM FOOD_WAREHOUSE WHERE ADDRESS LIKE '경기도%' ORDER BY WAREHOUSE_ID Colored by Color Scripter cs 2) oracle 1 2 3 4 SELECT WAREHOUSE_ID, WAREHOUSE_NAME, ADDRESS, NVL(FREEZER_YN,'N') FREEZER_YN FROM FOOD_WAREHOUSE WHERE ADDRESS LIKE '경기도%' ORDER BY WAREHOUSE_ID C..
2023.01.20