본문 바로가기

MySQL

SQL DISTINCT 및 논리연산자

728x90

DISTINCT

SELECT문의 결과값에서 특정 컬럼만 출력할 경우 중복된 값들이 나오는 경우에 이를 제거해서 표시하는 기능

select CountryCode from city where CountryCode="KOR";

select distinct CountryCode from city where CountryCode="KOR";

 

논리 연산자(AND,OR,NOT,IN,BETWEEN)

SELECT문의 조건절에 논리 조건 적용 해서 적용할 수 있는 연산자

select * from city where CountryCode="KOR" and Population>=1000000;

국가코드가 KOR이고 인구가 1000000만명 인 도시

select * from city where CountryCode="KOR" or CountryCode="JPN";
select * from city where CountryCode IN ("KOR","JPN");

국카코드가 KOR이거나 JPN인 도시

select * from city where CountryCode !="KOR"

국가코드가 KOR이 아닌 도시

select * from city where Population between 1000000 AND 5000000;

인구수가 100만명~500만명 사이인 도시

 

ORDER BY(desc:내림차순,asc:오름차순)

select * from city where CountryCode = "KOR" order by Population desc;

국가코드가 KOR인 도시들을 인구수 의 역순으로 출력

728x90