IN

1) all managers, supervisors를 나열할 때 → IN 사용 (아래 두 코드 다 사용 가능)

SELECT staffNo, fName, lName, position FROM Staff WHERE position IN(‘Manager’, ‘Supervisor’);
SELECT staffNo, fName, lName, position FROM staff WHERE position=‘Manager’ OR position=‘Supervisor’;

2) NOT IN

SELECT staffNo, fName, lName, position FROM Staff WHERE position NOT IN ('Manager', 'Supervisor');

IN은 많은 values를 포함하고 있을 때 더 효과적이다.

 

 

LIKE

1) 주소에 'Glasgow'가 포함된 owner를 찾고 싶을 때

SELECT clientNo, fName, lName, address, telNo
FROM PrivateOwner
WHERE address LIKE ‘%Glasgow%’;

2) 정확하게 딱 들어맞는 주소로 찾을 때

SELECT clientNo, fName, lName, address, telNo
FROM PrivateOwner
WHERE address LIKE '해당 주소';

3) 'Glasgow'가 포함된 주소로 찾을 때

SELECT clientNo, fName, lName, address, telNo
FROM PrivateOwner
WHERE address LIKE '%Glasgow%';

4) 특정 위치에 한 문자만 대신할 때 _ 사용

SELECT clientNo, fName, lName, address, telNo
FROM PrivateOwner
WHERE address LIKE '_G%';

 

IS NULL

NULL 값을 찾을 때

SELECT clinetNo, viewDate FROM viewing WHERE propertyNo=‘PG4’ AND comment IS NULL;

 

ODER BY

1) 모든 staff들에 대해 salary 내림차순으로 보고 싶을 때

SELECT staffNo, fName, lName, salary
FROM Staff
ORDER By Salary DESC;

2) 특정 속성의 순서대로 보고 싶을 때

`SELECT properyNo, type, rooms, rent,
FROM PropertyForRent
ORDER By type;

3) type으로 정렬한 후, 만일 type이 같다면 rent 내림차순으로 보고 싶을 때

SELECT propertyNo, type, rooms, rent
FROM propertyForRent
ORDER By type, rent DESC;

 

 

BELATED ARTICLES

more