[SQL] 10강 CONCAT, ALIAS, DISTINCT, LIMIT

JONGYOON JEON·2024년 2월 7일
0

SQL

목록 보기
2/13

CONCAT

여러 문자열을 하나로 합치거나 연결함

select concat(season,"-",episode,"(",broadcast_date,")") as '방송정보', concat(name,"(",job_title,")") as '출연  정보'
from celeb as c, snl_show as s where c.name=s.host;

ALIAS

칼럼이나 테이블이 길 경우 효율을 높이기 위해 사용

select name as '이름' from snl_show

as 생략도 가능

select name '이름' from celeb c;

ALIAS 예제 4

select season, episode, name, job_title from snl_show as s, celeb as c
    -> where c.name = s.host

ALIAS 예제 5

select concat(season,"-",episode,"(",broadcast_date,")") as '방송정보', concat(name,"(",job_title,")") as '출연자정보'
from celeb as c, snl_show as s 
where c.name=s.host;

문제 2

select agency '소속사 정보', concat('나이 : ',age,'(',sex,')') '신상정보', concat(season,'-',episode,', 방송날짜 :',broadcast_date) as '출연 정보' 
from celeb c,snl_show s 
where c.name=s.host 
and agency like '__엔터테이먼트' 
order by broadcast_date desc;

DISTINCT

중복을 제거해 준다

select distinct sex, job_title from celeb where job_title like '%배우%';

LIMIT

제한된 숫자만 가져오기

select * from celeb order by birthday limit 3;
select distinct concat('SNL 시즌 ',season,'에피소드',episode,'호스트 ', name) 'SNL 방송정보', age 
from celeb c, snl_show s 
where c.name=s.host 
order by age desc 
limit 2;
profile
효율적인 걸 좋아해요

0개의 댓글