SQL

MS SQL 실무_2편

Mara7 2022. 5. 21.
LIST

SQL
데이터베이스를 컨트롤해 데이터를 가져오고, 적재하고, 수정하는데 사용하는 언어

use study  #study라는 데이터베이스를 사용 
go # go 이전 코드 사용 후 다음 코드 실행 지정
select * from companyinfo

*구체적인 장소를 정하지 않으면 RDBMS는 로그인된 첫 번째 장소인 master 데이터베이스에 데이터를 요청

select name , City, IncInCtryCode 
from companyinfo

select distinct IncInCtryCode 
from companyinfo

select *from companyinfo 
where IncInCtryCode = 'kor'

select *from companyinfo
where Employees >=100000 

select * from companyinfo 
where IncInCtryCode ='kor' and Employees >50000

select * from companyinfo 
where City='seoul' or City = 'busan'

select * from companyinfo 
where not IncInCtryCode = 'usa'

select * from companyinfo 
where not IncInCtryCode ='usa' and not IncInCtryCode = 'jpn'

와일드 카드

다른 검색에 비해 오랜시간이 걸려서 성능을 저하시킬 수 있음.

반드시 필요한 경우가 아니라면 검색 패턴의 시작부분에는 쓰지 않는 것이 좋음.

select * from companyinfo
where name like 'a%'

select * from companyinfo 
where name like 'a____'

데이터 정렬

order by

오름차순이 기본, 생략하면 오름차순으로 정렬

오름차순 :  asc, 내림차순 : desc

정렬 조건 여러개 가능

select incinctrycode, employees, name 
from companyinfo 
order by incinctrycode

select incinctrycode, employees, name 
from companyinfo 
where incinctrycode is not null order by incinctrycode

select incinctrycode, employees, name 
from companyinfo
where IncInCtryCode is not null
order by incinctrycode, Employees DESC
반응형
LIST

'SQL' 카테고리의 다른 글

MS SQL 실무_6편  (0) 2022.06.21
MS SQL 실무_5편  (0) 2022.06.15
MS SQL 실무_4편  (0) 2022.06.06
MS SQL 실무_3편  (0) 2022.05.29
MS SQL 실무1  (0) 2022.05.14

댓글