특정 값이 포함되는 데이터를 조회하고자 할 때 사용하는 연산자
SELECT 컬럼명, 컬럼명
FROM 테이블명
WHERE 컬럼명 IN('데이터','데이터')
ex) MAKER 가 농심 또는 오뚜기인 상품의 정보들을 조회
NOT IN 연산자
특정 값이 포함되지않은 데이터를 조회하고자 할 때 사용
SELECT 컬럼명, 컬럼명
FROM 테이블명
WHERE 컬럼명 NOT IN('데이터','데이터')
ex) MAKER 가 농심 또는 오뚜기가 아닌 상품의 정보들을 조회
CREATE TABLE FOOD(
ID NUMBER PRIMARY KEY,
NAME VARCHAR2(100) NOT NULL,
MAKER VARCHAR2(100) NOT NULL,
PRICE NUMBER NOT NULL
)
create sequence food_seq;
insert into food(id,name,maker,price) values(food_seq.nextval,'후라이드','또래오래',15000);
insert into food(id,name,maker,price) values(food_seq.nextval,'소곱창','대한곱창',20000);
insert into food(id,name,maker,price) values(food_seq.nextval,'양념치킨','또래오래',16000);
insert into food(id,name,maker,price) values(food_seq.nextval,'참치회','이춘복참치',35000);
insert into food(id,name,maker,price) values(food_seq.nextval,'파닭','또래오래',17000);
insert into food(id,name,maker,price) values(food_seq.nextval,'미니전골','대한곱창',18000);
SELECT * FROM FOOD;
SELECT DISTINCT MAKER FROM FOOD;
SELECT * FROM FOOD WHERE MAKER IN ('또래오래', '대한곱창')
SELECT ID,NAME,MAKER,PRICE FROM FOOD WHERE MAKER ='대한곱창' OR MAKER='또래오래'
SELECT ID,NAME,MAKER,PRICE FROM FOOD WHERE MAKER NOT IN('대한곱창','또래오래')
SELECT ID, NAME, MAKER, PRICE FROM FOOD WHERE MAKER <> '대한곱창' AND MAKER <> '또래오래'
SELECT AVG(PRICE) FROM FOOD;
SELECT MAKER, AVG(PRICE) FROM FOOD GROUP BY MAKER;
SELECT MAKER FROM FOOD GROUP BY MAKER HAVING AVG(PRICE) < (SELECT AVG(PRICE) FROM FOOD)
SELECT NAME, PRICE, MAKER FROM FOOD WHERE MAKER IN (SELECT MAKER FROM FOOD GROUP BY MAKER HAVING AVG(PRICE) < (SELECT AVG(PRICE) FROM FOOD)) ORDER BY PRICE DESC;
SELECT * FROM JDBC_EMPLOYEE
SELECT JOB FROM JDBC_EMPLOYEE GROUP BY JOB HAVING COUNT(JOB) >=3
SELECT EMPNO, NAME, JOB, SALARY
FROM JDBC_EMPLOYEE
WHERE JOB IN
(SELECT JOB
FROM JDBC_EMPLOYEE
GROUP BY JOB
HAVING COUNT(JOB) >=3)
ORDER BY SALARY DESC;