MS-SQL문 강좌 1, 2 장
select title_id, convert(char(30), title), type -- 타이틀 부분을 30자로 잘라서 보여줌(제목은 type)
from titles
select 'a'+'b' -- 문자 a 와 b를 더함(결과 :ab)
select 'a'+char(13)+'b'+char(10) --a문자에 문자형 13을 더하고 b에 문자형 10을 더한다(결과 : a [엔터] b)
select dateadd(m, 100, getdate()) -- 현재 날짜에서 100일을 더한 날수 (달수를 출력하기위해 dateadd 명령사용)
select datediff(d, '1965.6.27', getdate()) -- 현재 날짜에서 태어난 날짜 계산 d 는 날짜형(결과 : 살아온 날수)
select convert(char(30), getdate(), 102) --
select pubdate, convert(char(30), pubdate, 102) --pubdate가 30자리로 잘려진 102번 형식(도움말나옴)으로 출력
from titles
select title_id, qty
from sales
where title_id >='TC4000' -- 아이디가 tc4000번 이상은 출력 (ex. tc4001 tc4002...)
where qty >= 25
select title_id, qty -- where절에 in 을 사용하여 같은 아이디만을 검색
from sales
where title_id in('ps2091' , 'mc3021', 'tc7777')
select title -- 타이틀에 computer가 들어간 문장을 검색
from titles
where title like '%computer%'
select distinct type -- 같은 이름의 타이틀을 한개씩만 출력
from titles
select distinct city, state --한줄에 distinct가 적용되며 시티와 스테이트에서 다른항목들만 출력
from authors
select pubdate, year(pubdate) -- where 절에는 필드값 다음 바로 연산기호사용
from titles
where pubdate>='91.1.1' and pubdate< '92.1.1'
select title_id, price*1.1 --부가가치세계산
from titles
where price>20/1.1 --price 가 20보다 큰값을 찾은 뒤 1.1로 나눠준다.