# 0526 til

looggi·2023년 5월 26일
0

목록 보기
78/114

## SQL 문제풀기

### 루시와 엘라 찾기

-- https://school.programmers.co.kr/learn/courses/30/lessons/59046

SELECT animal_id, name, sex_upon_intake
from animal_ins
where name in ('Lucy', 'Ella', 'Pickle', 'Rogan', 'Sabrina', 'Mitty')
order by animal_id

### 이름에 el 들어가는 동물 찾기

-- https://school.programmers.co.kr/learn/courses/30/lessons/59047

SELECT animal_id, name
from animal_ins
where animal_type='dog' and name like '%el%'
order by name

### 중성화 여부 파악하기

-- https://school.programmers.co.kr/learn/courses/30/lessons/59409

-- if
SELECT animal_id,
name,
if (sex_upon_intake like '%Spayed%'or sex_upon_intake like'%Neutered%','O','X') as '중성화'
from animal_ins
order by animal_id

-- case when
SELECT animal_id,
name,
(case
when sex_upon_intake like '%Spayed%'or sex_upon_intake like'%Neutered%' then 'O'
else 'X'
end) as '중성화'
from animal_ins
order by animal_id

-- regex
SELECT  ANIMAL_ID,
NAME,
(CASE
WHEN SEX_UPON_INTAKE REGEXP 'Neutered|Spayed' THEN 'O' ELSE 'X'
END) AS 중성화
FROM ANIMAL_INS
ORDER BY ANIMAL_ID

헐 칼럼 이름 붙일 때 '따옴표 안써도 된다..' 허걱..스..스.슷.ㅡㅅ.ㅡ...

looooggi