Programmers(49)
-
[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 -
문자열 내 p와 y의 개수
문제 결과 1 2 3 4 5 6 7 class Solution { boolean solution(String s) { s=s.toUpperCase(); return s.replace("P", "").length() == s.replace("Y", "").length(); } } Colored by Color Scripter cs 입력 받은 문자열을 모두 대문자로 치환한다. replace로 각각 P, Y를 제외한 문자열의 길이를 구한다. 그리고 [P를 제외한 문자열의 길이] == [P를 제외한 문자열의 길이] 라면 true 아니면 false를 반환한다. 그리고 다른 분들이 작성한 코드를 보다가 toUpperCase()를 사용하지 않는 방법을 알게 됐다. 1 2 3 4 5 6 7 class Solution ..
2023.01.21 -
[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 -
[oracle/mysql]입양 시각 구하기(2)
쉬울 줄 알았으나 굉장히 오랜 시간을 들인 문제 특히 mysql 코드를 공들여 쉽게 설명하였으니 @set 함수를 사용하는 것에 어려움을 느꼈다면 꼭 끝까지 읽었으면 하는 바람이다. 문제 결과 당연히 시간별로 GROUP BY 해서 COUNT로 하면 나올 줄 알았더니 그렇게 하면 데이터가 없는 시간은 출력되지 않는다. 1 2 3 4 5 SELECT to_char(datetime, 'HH24') datetime, count(animal_id) count from animal_outs CONNECT BY LEVEL =24 group by to_char(datetime, 'HH24') order by datetime Colored by Color Scripter cs 1) ORACLE 1 2 3 4 5 6 7 8..
2023.01.20