엄지월드

DB 명령어 본문

Server&DevOps/Database

DB 명령어

킨글 2022. 7. 3. 09:48

공백을 제거하고 length가 0인 eng_title을 찾아서 count(*)로 표시해주기

select count(*)
from movie
-- where eng_title is null or trim(eng_title) = ''
where length(trim(eng_title)) = 0 
;

 

and 사용 및 like 사용

select *
from movie m 
where country ='한국'
	and pub_year = 2001
	and genre like '%액션%'

 

in을 활용하여 select 문 2개 합치기 

select *
from actor a 
where `domain` ='감독'
	and name in(
		select director
		from movie m 
		where production like '%싸이더스%'
			and pub_year = 2020
	)
;

 

distinct, groupby를 사용하여 중복 제거

select distinct domain
from actor a
where domain is not null and trim(domain) <> ''
;
select domain
from actor
where domain is not null and trim(domain) <> ''
group by domain
;

 

join을 사용하여 SQL문을 2개 합친 후에 order by를 사용하여 정렬

select *
from movie
where pub_year > 2020
;

select *
from actor
where domain = '감독'
	and country = '독일'
;
select m.title, m.director, m.pub_year, m.genre, m.pub_year
from movie m
	join actor a on (m.director = a.name and a.domain = '감독')
where m.pub_year > 2020
	and a.country = '독일'
order by m.pub_year desc   
;

 

case

Comments