sql 코드카타 내배캠28

포도당·2025년 5월 29일
0

개중에 이름에 el이 들어가는 개 찾기
select animal_id,
name
from animal_ins
where name like '%el%' AND animal_type = 'dog'
order by name

여러 다중 조건은 AND 절 이용.

null 값을 세기

select count(*)
from user_info
where age is NULL

##having 과 where 그리고 group바이의 차이점

쉽게말해 group by 사용시 조건을 걸어주는 것이 havig
where 절은 개별 행에 대한 즉 그룹없는 행의 조건

이름에 null값을 다른 값으로 바꾸기

case when 사용시 행이 하나 더만들어짐
select animal_type,
name,
sex_upon_intake,
case
when name is NULL then 'No name'
else name
end a
from animal_ins
order by animal_id;

여기서 알게된 점은 when다음에는 행이 온다는 점.

ifnull 함수를 썼으나 행이 만들어진느 건 똑같고

그냥 이걸로 name을 대체하면될듯
select
animal_type,
ifnull(name, 'No name') as name,
sex_upon_intake
from animal_ins
order by animal_id;

  1. 만약 네임 행에 널이 있따면 노네임으로 바꿔줘.
profile
어디까지 성장할 것 인가..!

0개의 댓글