Notice
Recent Posts
Recent Comments
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[50~55] 230310~230317 SQL ๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ (๋ฐ์ดํ„ฐ: Employer, Department) [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 50์ผ~55์ผ] ๋ณธ๋ฌธ

๐ŸŒณBootcamp Revision 2023โœจ/Python, Flask, SQL

[50~55] 230310~230317 SQL ๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ (๋ฐ์ดํ„ฐ: Employer, Department) [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 50์ผ~55์ผ]

yjyuwisely 2023. 3. 13. 12:44

์ฐธ๊ณ : https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=zinuriu2&logNo=221659075746

230310 Fri 50th class

1. EMP ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์–ด๋ณด์ž (Employer)

EMPNO  ENAME  JOB  MGR  HIREDATE  SAL  COMM  DEPTNO
7369 SMITH CLERK 7902 1980-12-17 0:00 800 NULL 20
์ค‘๋žต
7839 KING PRESIDENT NULL 1981-11-17 0:00 5000 NULL 10

์ˆซ์ž๋กœ ๊ตฌ์„ฑ๋œ ๊ฒƒ: EMPNO, MGR, SAL, COMM, DEPTNO
NULL ์—†๋Š” ์—ด: EMPNO, ENAME, JOB, HIREDATE, SAL, DEPTNO
NULL ์žˆ๋Š” ์—ด: MGR, COMM

EMPNO ์—ด์€ ๊ธฐ๋ณธํ‚ค(UNIQUE & NOT NULL)์ž„
๋‚˜๋จธ์ง€ ์ œ์•ฝ ์กฐ๊ฑด์€ ์œ„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ํŒ๋‹จํ•ด๋ณด์ž.

2. DEPT ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์–ด๋ณด์ž (Department)

DEPTNO  DNAME  LOC 
10 ACCOUNTANT NEW YORK
์ค‘๋žต
50 DEVELOPEMENT KOREA

์ˆซ์ž๋กœ ๊ตฌ์„ฑ๋œ ๊ฒƒ: DEPTNO
DEPTNO ์—ด์€ ๊ธฐ๋ณธํ‚ค์ž„
๋‚˜๋จธ์ง€ ์ œ์•ฝ ์กฐ๊ฑด์€ ์œ„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ํŒ๋‹จํ•ด๋ณด์ž.

์ฐธ๊ณ 


230313 Mon 51st class

๋ฌธ์ œ ํ’€๊ธฐ)

INSERT INTO

์ฐธ๊ณ : https://www.w3schools.com/sql/sql_insert.asp

๋ฐ์ดํ„ฐ 
์ฐธ๊ณ : https://bigdatansql.com/2021/08/16/emp-and-dept-datasets-for-mysql/

ํ…Œ์ด๋ธ” ์™„์„ฑ ์ฝ”๋“œ)

-- Creating EMP table.
CREATE TABLE EMP(
    EMPNO INT, -- empno INT,
    ENAME varchar(30) NOT NULL, -- ename VARCHAR(10),
	JOB varchar(30) NOT NULL, -- job VARCHAR(9),
    MGR int, -- mgr INT,
    HIREDATE date NOT NULL, -- hiredate DATE,
    SAL DECIMAL(7,2), -- sal DECIMAL(7,2),
    COMM DECIMAL(7,2), -- comm DECIMAL(7,2),
    DEPTNO int NOT NULL, -- deptno INT,
    CONSTRAINT pkey_EMPNO PRIMARY KEY(EMPNO) -- constraint pk_emp primary key (empno),
    -- PRIMARY KEY(๊ธฐ๋ณธํ‚ค) : UNIQUE & NOT NULL 
);

-- Creating DEPT table.
CREATE TABLE DEPT(
    DEPTNO int, -- deptno INT,
    DNAME varchar(30) NOT NULL, -- dname VARCHAR(14),
    LOC varchar(30) NOT NULL, -- loc VARCHAR(13),
    CONSTRAINT pkey_DEPTNO PRIMARY KEY(DEPTNO) -- constraint pk_dept primary key (deptno)
    -- PRIMARY KEY(๊ธฐ๋ณธํ‚ค) : UNIQUE & NOT NULL
);

-- Data Insertion in EMP table
INSERT INTO EMP VALUES
(7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800, null, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '1981-02-20', 1600, 300, 30),
(7521, 'WARD', 'SALESMAN', 7698, '1981-02-22', 1250, 500, 30),
(7566, 'JONES', 'MANAGER', 7839, '1981-04-02',2975, null, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, '1981-09-28', 1250, 1400, 30),
(7698, 'BLAKE', 'MANAGER', 7839, '1981-05-01', 2850, null, 30),
(7782, 'CLARK', 'MANAGER', 7839, '1981-06-09', 2450, null, 10),
(7788, 'SCOTT', 'ANALYST', 7566, '1981-04-19',3000, null, 20),
(7839, 'KING', 'PRESIDENT', null, '1981-11-17', 5000, null, 10),
(7844, 'TURNER', 'SALESMAN', 7698, '1981-09-08', 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, '1987-05-23', 1100, null, 20),
(7900, 'JAMES', 'CLERK', 7698, '1981-03-12', 950, null, 30),
(7902, 'FORD', 'ANALYST', 7566, '1981-03-12', 3000, null, 20),
(7934, 'MILLER', 'CLERK', 7782, '1982-01-23', 1300, null, 10);

-- Data Insertion in DEPT table
INSERT INTO DEPT(DEPTNO, DNAME, LOC) VALUES 
(10, 'ACCOUNTING', 'NEW YORK'),
(20, 'RESEARCH', 'DALLAS'),
(30, 'SALES', 'CHICAGO'),
(40, 'OPERATIONS', 'BOSTON'),
(50, 'DEVELOPERS', 'KOREA');

๊ฒฐ๊ณผ)

EMP ํ…Œ์ด๋ธ”
DEPT ํ…Œ์ด๋ธ”


๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ)

์ฐธ๊ณ :
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=zinuriu2&logNo=221659075746

Q1 ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 10๋ฒˆ์ธ ๋ถ€์„œ์˜ ์‚ฌ๋žŒ ์ค‘ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ์›”๊ธ‰์„ ์ถœ๋ ฅํ•˜์„ธ์š”.

select EMPNO, ENAME, SAL from EMP where DEPTNO = 10;


Q2 ์‚ฌ์›๋ฒˆํ˜ธ๊ฐ€ 7369์ธ ์‚ฌ๋žŒ ์ค‘ ์ด๋ฆ„, ์ž…์‚ฌ์ผ, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select ENAME, HIREDATE, DEPTNO from EMP where EMPNO = 7369;

์ •๋‹ต์—์„  '7369'๋กœ ๋‚˜์˜จ๋‹ค. ์ด์œ ๋Š” ์ •๋‹ต์—์„œ๋Š” EMPNO๋ฅผ VARCHAR(4) PRIMARY KEY๋กœ ๋’€๊ณ  ๋‚˜๋Š” INT๋กœ ๋’€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

select ENAME, HIREDATE, DEPTNO from EMP where EMPNO = '7369';

Q3 ์ด๋ฆ„์ด ALLEN์ธ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where ENAME = 'ALLEN';


Q4 ์ž…์‚ฌ์ผ์ด 83/01/12์ธ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„, ๋ถ€์„œ๋ฒˆํ˜ธ,์›”๊ธ‰์„ ์ถœ๋ ฅํ•˜์„ธ์š”.

select ENAME, DEPTNO, SAL from EMP where HIREDATE = '1983-01-12';


Q5 ์ง์—…์ด MANAGER๊ฐ€ ์•„๋‹Œ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where JOB <> 'MANAGER';

Technically there is no difference between != and <>
์ •๋‹ต์—์„  ์•„๋ž˜ ์ฝ”๋“œ๋„ ๋‚˜์˜จ๋‹ค.

select * from EMP where JOB != 'MANAGER';

Q6 ์ด๋ฆ„์ด K๋กœ ์‹œ์ž‘ํ•˜๋Š” ์‚ฌ๋žŒ๋ณด๋‹ค ๋†’์€ ์ด๋ฆ„์„ ๊ฐ€์ง„ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where ENAME > 'K';

๋˜‘๊ฐ™์€ ๋‹ต์€ ๋‚˜์˜ค๋Š”๋ฐ ์ •๋‹ต์—์„œ๋Š” 'K%'์ด๋‹ค.

select * from EMP where ENAME > 'K%';

Q7 ์ž…์‚ฌ์ผ์ด 81/04/02 ๋ณด๋‹ค ๋Šฆ๊ณ  82/12/09 ๋ณด๋‹ค ๋น ๋ฅธ ์‚ฌ์›์˜ ์ด๋ฆ„, ์›”๊ธ‰, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select ENAME, SAL, DEPTNO from EMP where '1981-04-02' < HIREDATE and HIREDATE < '1982-12-09';


Q8 ์ด๋ฆ„ ์ค‘ S์ž๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ์‚ฌ๋žŒ๋งŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where ENAME like '%S%';


Q9 ์ด๋ฆ„์ด S๋กœ ์‹œ์ž‘ํ•˜๊ณ  ๋งˆ์ง€๋ง‰ ๊ธ€์ž๊ฐ€ T์ธ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”(๋‹จ ์ด๋ฆ„์€ ์ „์ฒด 5์ž๋ฆฌ)

select * from EMP where ENAME like "S____" and ENAME like "____T";

์ •๋‹ต์—์„œ๋Š” ๋‘ ์กฐ๊ฑด์„ ํ•ฉ์นœ ๊ฑธ๋กœ ๋‚˜์˜จ๋‹ค.

select * from EMP where ENAME like "S___T";

Q10 ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋Š” ๊ด€๊ณ„์—†๊ณ  ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๊ฐ€ A์ธ ์‚ฌ๋žŒ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where ENAME like "_A%";


Q11 ์ด๋ฆ„์˜ ์ฒซ ๊ธ€์ž๊ฐ€ K๋กœ ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 30์ธ ์‚ฌ๋žŒ์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select EMPNO, ENAME, DEPTNO from EMP where ENAME like "K%" or DEPTNO = 30;


Q12 ๊ธ‰์—ฌ๊ฐ€ 1500์ด์ƒ์ด๊ณ , ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 30๋ฒˆ์ธ ์‚ฌ์› ์ค‘ ์ง์—…์ด MANAGER์ธ ์‚ฌ๋žŒ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where SAL >= 1500 and DEPTNO = 30 and JOB = 'MANAGER';


Q13 ์‚ฌ์›๋ฒˆํ˜ธ๊ฐ€ 7654์™€ 7782 ์‚ฌ์ด ์ด์™ธ์˜ ์‚ฌ์›์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where not EMPNO between 7654 and 7782;


Q14 ์ด๋ฆ„์ด B์™€ J์‚ฌ์ด์˜ ๋ชจ๋“  ์‚ฌ์›์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where 'B' < ENAME and ENAME < 'J'; 
select * from EMP where ENAME between 'B' and 'J';

์ •๋‹ต์—์„œ๋Š” 'B%', 'J%'๋ฅผ ์ผ๋‹ค.

select * from EMP where 'B%' < ENAME and ENAME < 'J%';

Q15 ์ž…์‚ฌ์ผ์ด 81๋…„ ์ด์™ธ์— ์ž…์‚ฌํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where not HIREDATE between '1981-01-01' and '1981-12-31';


Q16 ์ง์—…์ด MANAGER์™€ SALESMAN์ธ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where JOB = 'MANAGER' or JOB = 'SALESMAN';


Q17 ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 20,30๋ฒˆ์„ ์ œ์™ธํ•œ ๋ชจ๋“  ์‚ฌ๋žŒ์˜ ์ด๋ฆ„, ์‚ฌ์›๋ฒˆํ˜ธ, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select ENAME, EMPNO, DEPTNO from EMP where not (DEPTNO = 20 or DEPTNO = 30);
select ENAME, EMPNO, DEPTNO from EMP where not DEPTNO between 20 and 30;


Q18 ์ด๋ฆ„์ด S๋กœ ์‹œ์ž‘ํ•˜๋Š” ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ์ž…์‚ฌ์ผ, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select EMPNO, ENAME, HIREDATE, DEPTNO from EMP where ENAME like "S%";


Q19 ์ž…์‚ฌ์ผ์ด 81๋…„๋„์ธ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where HIREDATE like '1981%';
select * from EMP where HIREDATE between '1981-01-01' and '1981-12-31';


Q20 ์ด๋ฆ„ ์ค‘ S์ž๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ์‚ฌ๋žŒ์ธ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where ENAME like "%S%";


Q21 ์ด๋ฆ„์ด S๋กœ ์‹œ์ž‘ํ•˜๊ณ  ๋งˆ์ง€๋ง‰ ๊ธ€์ž๊ฐ€ T์ธ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”(๋‹จ ์ด๋ฆ„์€ ์ „์ฒด 5์ž๋ฆฌ์ด๋‹ค.)

select * from EMP where ENAME like "S___T";


Q22 ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋Š” ๊ด€๊ณ„์—†๊ณ  ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๊ฐ€ A์ธ ์‚ฌ๋žŒ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where ENAME like "_A%";


Q23 ์ปค๋ฏธ์…˜์ด NULL์ธ ์‚ฌ๋žŒ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”

select * from EMP where COMM is NULL;


Q24 ์ปค๋ฏธ์…˜์ด NULL์ด ์•„๋‹Œ ์‚ฌ๋žŒ์˜ ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where not COMM is NULL;

๊ฒฐ๊ณผ๋Š” ๊ฐ™์€๋ฐ ์ •๋‹ต์—์„œ๋Š” is not์„ ์ผ๋‹ค.

select * from EMP where COMM is not NULL;

Q25 ๋ถ€์„œ๊ฐ€ 30๋ฒˆ ๋ถ€์„œ์ด๊ณ , ๊ธ‰์—ฌ๊ฐ€ 1500 ์ด์ƒ์ธ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„, ๋ถ€์„œ, ์›”๊ธ‰์„ ์ถœ๋ ฅํ•˜์„ธ์š”.

select ENAME, DEPTNO, SAL from EMP where DEPTNO = 30 and SAL >= 1500;

 


Q26 ์ด๋ฆ„์˜ ์ฒซ ๊ธ€์ž๊ฐ€ K๋กœ ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 30์ธ ์‚ฌ๋žŒ์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select EMPNO, ENAME, DEPTNO from EMP where ENAME like "K%" or DEPTNO = 30;


Q27 ๊ธ‰์—ฌ๊ฐ€ 1500์ด์ƒ์ด๊ณ , ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 30๋ฒˆ์ธ ์‚ฌ์› ์ค‘ ์ง์—…์ด MANAGER์ธ ์‚ฌ๋žŒ์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

select * from EMP where SAL >= 1500 and DEPTNO = 30 and JOB = 'MANAGER';


230314 TUE 52nd class

๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ)
emp ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉ

Q1 10๋ฒˆ ๋ถ€์„œ์™€ ๊ฐ™์€ ์ผ์„ ํ•˜๋Š” ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๋ถ€์„œ๋ช…, ๊ธ‰์—ฌ๋ฅผ ์กฐํšŒํ•˜๊ณ  ๊ธ‰์—ฌ๊ฐ€ ๋งŽ์€ ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”.


Q2 ๊ธ‰์—ฌ๊ฐ€ 3000์ด์ƒ์ด๋ฉด, ๊ธ‰์—ฌ + ๊ธ‰์—ฌ์˜ 15%์˜ ๊ฒฉ๋ ค๊ธˆ์„,
๊ธ‰์—ฌ๊ฐ€ 2000์ด์ƒ์ด๋ฉด, ๊ธ‰์—ฌ + ๊ธ‰์—ฌ์˜ 10%์˜ ๊ฒฉ๋ ค๊ธˆ์„,
๊ธ‰์—ฌ๊ฐ€ 1000์ด์ƒ์ด๋ฉด, ๊ธ‰์—ฌ + ๊ธ‰์—ฌ์˜ 5%์˜ ๊ฒฉ๋ ค๊ธˆ์„,
๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๊ธ‰์—ฌ๋ฅผ ๊ตฌํ•˜์—ฌ, ์ด๋ฆ„, ์ง์—…, ๊ธ‰์—ฌ, ๊ฒฉ๋ ค๊ธˆ์„ ํ‘œ์‹œํ•˜์‹œ์˜ค.

์ •๋‹ต์ฒ˜๋Ÿผ ํ•ด๋„ ๊ฐ’์€ ๊ฐ™๋‹ค.


Q3 ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ์—ฐ๋ด‰์„ ์—ฐ๋ด‰์ด ๋†’์€ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ์ถœ๋ ฅํ•˜์„ธ์š”.
(์—ฐ๋ด‰์€ sal * 12 + comm์œผ๋กœ ๊ณ„์‚ฐ)

COALESCE(COMM, 0)์œผ๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋„์ถœํ–ˆ๋‹ค.
IFNULL(COMM, 0)์œผ๋กœ๋„ ๊ฒฐ๊ณผ๋ฅผ ๋„์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฒ˜์Œ์— ํ•œ๊ธ€๋กœ ๋ณ€์ˆ˜๋ช…์„ ์ ์—ˆ๋Š”๋ฐ "" ์•ˆ ์“ฐ๋‹ˆ๊นŒ ์ •๋‹ต ๋‚˜์™”๋‹ค.
๊ต์žฌ์—์„œ๋Š” ํ•œ๊ธ€ ๋ณ€์ˆ˜๋กœ ์“ฐ๋Š” ๊ฑฐ ๋น„์ถ”๋‹ˆ๊นŒ ์•ˆ ์จ์•ผ๊ฒ ๋‹ค.

์•„๋ž˜๊ฐ€ ์ด์ƒ์ ์ธ ์ •๋‹ต์ด๋‹ค.

๋‘ ์ฝ”๋“œ์˜ ๋‹ต์€ ๋˜‘๊ฐ™์ด ๋‚˜์˜จ๋‹ค.


ํ•™์›์˜ ์ •๋‹ต


230317 Fri 55th Class

1) 'ALLEN'์˜ ์ง๋ฌด์™€ ๊ฐ™์€ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„, ๋ถ€์„œ๋ช…, ๊ธ‰์—ฌ, ์ง๋ฌด๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

2) JONES๊ฐ€ ์†ํ•ด์žˆ๋Š” ๋ถ€์„œ์˜ ๋ชจ๋“  ์‚ฌ๋žŒ์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ์ž…์‚ฌ์ผ, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.

3) ์ „์ฒด ์‚ฌ์›์˜ ํ‰๊ท  ์ž„๊ธˆ๋ณด๋‹ค ๋งŽ์€ ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๋ถ€์„œ๋ช…, ์ž…์‚ฌ์ผ, ์ง€์—ญ, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.


4) 10๋ฒˆ ๋ถ€์„œ์™€ ๊ฐ™์€ ์ผ์„ ํ•˜๋Š” ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๋ถ€์„œ๋ช…, ์ง€์—ญ, ๊ธ‰์—ฌ๋ฅผ ๊ธ‰์—ฌ๊ฐ€ ๋งŽ์€ ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”.


5) 'MARTIN'์ด๋‚˜ 'SCOTT'์˜ ๊ธ‰์—ฌ์™€ ๊ฐ™์€ ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.


6) ๋ถ€์„œ๋ฒˆํ˜ธ๊ฐ€ 30๋ฒˆ ๋ถ€์„œ์˜ ์ตœ๊ณ  ๊ธ‰์—ฌ๋ณด๋‹ค ๋†’์€ ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜์„ธ์š”.


7) ์‚ฌ์›์ค‘์—์„œ ๊ธ‰์—ฌ(sal)์™€ ๋ณด๋„ˆ์Šค(comm)์„ ํ•ฉ์นœ ๊ธˆ์•ก์ด ๊ฐ€์žฅ ๋งŽ์€ ๊ฒฝ์šฐ์™€ ๊ฐ€์žฅ ์ ์€ ๊ฒฝ์šฐ, ํ‰๊ท  ๊ธˆ์•ก์„ ๊ตฌํ•˜์„ธ์š”.

HINT : IFNULL์‚ฌ์šฉ(๊ตฌ๊ธ€๋กœ ๊ฒ€์ƒ‰ํ•ด๋ณด์„ธ์š”.)

8) ๋ถ€์„œ๋ณ„๋กœ ๊ธ‰์—ฌํ•ฉ๊ณ„๋ฅผ ๊ตฌํ•˜์„ธ์š”.


9) ๊ธ‰์—ฌ๊ฐ€ 3000์ด์ƒ์ด๋ฉด, ๊ธ‰์—ฌ+๊ธ‰์—ฌ์˜ 15%์˜ ๊ฒฉ๋ ค๊ธˆ์„, ๊ธ‰์—ฌ๊ฐ€ 2000์ด์ƒ์ด๋ฉด, ๊ธ‰์—ฌ+๊ธ‰์—ฌ์˜ 10%์˜ ๊ฒฉ๋ ค๊ธˆ์„,๊ธ‰์—ฌ๊ฐ€ 1000์ด์ƒ์ด๋ฉด, ๊ธ‰์—ฌ+๊ธ‰์—ฌ์˜ 5%์˜ ๊ฒฉ๋ ค๊ธˆ์„, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๊ธ‰์—ฌ๋ฅผ ๊ตฌํ•˜์—ฌ,

   ์ด๋ฆ„, ์ง์—…, ๊ธ‰์—ฌ,๊ฒฉ๋ ค๊ธˆ์„ ํ‘œ์‹œํ•˜์‹œ์˜ค.
HINT : CASE WHEN์‚ฌ์šฉ(๊ตฌ๊ธ€๋กœ ๊ฒ€์ƒ‰ํ•ด๋ณด์„ธ์š”.)

10) 'MARTIN'๊ณผ ๊ฐ™์€ ๋งค๋‹ˆ์ €์™€ ์ผํ•˜๋Š” ์ด๋ฆ„, ์ง์—…, ๊ธ‰์—ฌ, ๋ถ€์„œ๋ช…, ์ง€์—ญ์„ ๊ตฌํ•˜์„ธ์š”.


11) ๋ถ€์„œ๋ช…์ด 'RESEARCH'์ธ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„, ์ง์—…, ๊ธ‰์—ฌ,๋ถ€์„œ๋ช…์„ ํ‘œ์‹œํ•˜์‹œ์˜ค.


12) ๊ฐ ๋ถ€์„œ๋ณ„ ํ‰๊ท  ๊ธ‰์—ฌ๋ฅผ ๊ตฌํ•˜๊ณ , ๊ทธ ์ค‘์—์„œ ํ‰๊ท  ๊ธ‰์—ฌ๊ฐ€ ๊ฐ€์žฅ ์ ์€ ๋ถ€์„œ    ์˜ ํ‰๊ท  ๊ธ‰์—ฌ๋ณด๋‹ค ์ ๊ฒŒ ๋ฐ›๋Š” ์‚ฌ์›๋“ค์˜ ๋ถ€์„œ๋ช…, ์ง€์—ญ, ๊ธ‰์—ฌ๋ฅผ ๊ตฌํ•˜์„ธ์š”.


13) 'BLAKE'์™€ ๊ฐ™์€ ๋ถ€์„œ์— ์žˆ๋Š” ์‚ฌ์›๋“ค์˜ ์ด๋ฆ„๊ณผ ๊ณ ์šฉ์ผ์„ ๋ฝ‘๋Š”๋ฐ 'BLAKE'๋Š” ๋นผ๊ณ  ์ถœ๋ ฅํ•˜๋ผ.


14) ์ด๋ฆ„์— 'T'๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ์‚ฌ์›๋“ค๊ณผ ๊ฐ™์€ ๋ถ€์„œ์—์„œ ๊ทผ๋ฌดํ•˜๊ณ ์žˆ๋Š” ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ์™€ ์ด๋ฆ„์„ ์ถœ๋ ฅํ•˜๋ผ.


15) ์ž์‹ ์˜ ๊ธ‰์—ฌ๊ฐ€ ํ‰๊ท  ๊ธ‰์—ฌ๋ณด๋‹ค ๋งŽ๊ณ , ์ด๋ฆ„์— 'S'๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ์‚ฌ์›๊ณผ ๋™์ผํ•œ ๋ถ€์„œ์—์„œ ๊ทผ๋ฌดํ•˜๋Š” ๋ชจ๋“  ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ.


16) ์ปค๋ฏธ์…˜์„ ๋ฐ›๋Š” ์‚ฌ์›๊ณผ ๋ถ€์„œ๋ฒˆํ˜ธ, ์›”๊ธ‰์ด ๊ฐ™์€ ์‚ฌ์›์˜ ์ด๋ฆ„, ์›”๊ธ‰, ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ.


17) ์ง์—…๋ช…๊ณผ ์‚ฌ์›์˜ ๋“ฑ๊ธ‰์„ ์ง์—…์ด 'PRESIDENT' ์ด๋ฉด 'A', ์ง์—…์ด 'ANALYST' ์ด๋ฉด 'B', ์ง์—…์ด 'MANAGER' ์ด๋ฉด 'C', ์ง์—…์ด 'SALESMAN' ์ด๋ฉด 'D', ์ง์—…์ด 'CLEARK' ์ด๋ฉด 'E' ๋กœ ํ‘œ์‹œํ•˜์‹œ์˜ค.


18) 10๋ฒˆ ๋ถ€์„œ์ค‘์—์„œ 30๋ฒˆ ๋ถ€์„œ์—๋Š” ์—†๋Š” ์—…๋ฌด๋ฅผ ํ•˜๋Š” ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๋ถ€์„œ๋ช…,์ž…์‚ฌ์ผ, ์ง€์—ญ์„ ์ถœ๋ ฅํ•˜๋ผ.


19) ๊ธ‰์—ฌ๊ฐ€ 30๋ฒˆ ๋ถ€์„œ์˜ ์ตœ๊ณ  ๊ธ‰์—ฌ๋ณด๋‹ค ๋†’์€ ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ.


20) ๊ธ‰์—ฌ๊ฐ€ 30๋ฒˆ ๋ถ€์„œ์˜ ์ตœ์ € ๊ธ‰์—ฌ๋ณด๋‹ค ๋‚ฎ์€ ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ.


21) ์‚ฌ์› ์ค‘์—์„œ ์ž…์‚ฌ์ผ์ด ๊ฐ€์žฅ ๋น ๋ฅธ ์‚ฌ์›์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ์ž…์‚ฌ์ผ, ๋ถ€์„œ๋ช…์„ ์ถœ๋ ฅํ•˜์„ธ์š”.


22) ํ‰๊ท  ์—ฐ๋ด‰๋ณด๋‹ค ๋งŽ์ด ๋ฐ›๋Š” ์‚ฌ์›๋“ค์˜ ์‚ฌ์›๋ฒˆํ˜ธ, ์ด๋ฆ„, ์—ฐ๋ด‰์„ ์—ฐ๋ด‰์ด ๋†’์€ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ์ถœ๋ ฅํ•˜์„ธ์š”.

(์—ฐ๋ด‰์€ sal*12+comm์œผ๋กœ ๊ณ„์‚ฐ)
HINT : IFNULL์‚ฌ์šฉ(๊ตฌ๊ธ€๋กœ ๊ฒ€์ƒ‰ํ•ด๋ณด์„ธ์š”.)

23) EMP์™€ DEPT TABLE์„ JOINํ•˜์—ฌ ๋ถ€์„œ ๋ฒˆํ˜ธ, ๋ถ€์„œ๋ช…, ์ด๋ฆ„, ๊ธ‰์—ฌ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ.


24) ์ด๋ฆ„์ด 'ALLEN'์ธ ์‚ฌ์›์˜ ๋ถ€์„œ๋ช…์„ ์ถœ๋ ฅํ•˜๋ผ.


25) DEPT Table ์—๋Š” ์กด์žฌํ•˜๋Š” ๋ถ€์„œ์ฝ”๋“œ์ด์ง€๋งŒ ํ•ด๋‹น๋ถ€์„œ์— ๊ทผ๋ฌดํ•˜๋Š” ์‚ฌ๋žŒ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์˜ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ.

728x90
๋ฐ˜์‘ํ˜•

'๐ŸŒณBootcamp Revision 2023โœจ > Python, Flask, SQL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

*[53] 230315 SQL Ch 4. ๋ฐ์ดํ„ฐ์˜ ์ถ”๊ฐ€, ์‚ญ์ œ, ๊ฐฑ์‹ : 16๊ฐ• ํ–‰ ์ถ”๊ฐ€ํ•˜๊ธฐ - INSERT, 17๊ฐ• ์‚ญ์ œํ•˜๊ธฐ - DELETE, 18๊ฐ• ๋ฐ์ดํ„ฐ ๊ฐฑ์‹ ํ•˜๊ธฐ - UPDATE, 19๊ฐ• ๋ฌผ๋ฆฌ์‚ญ์ œ์™€ ๋…ผ๋ฆฌ์‚ญ์ œ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 53์ผ]  (0) 2023.03.15
[52] 230314 SQL Ch 3. ์ •๋ ฌ๊ณผ ์—ฐ์‚ฐ: 9๊ฐ• ์ •๋ ฌ - ORDER BY, 10๊ฐ• ๋ณต์ˆ˜์˜ ์—ด์„ ์ง€์ •ํ•ด ์ •๋ ฌํ•˜๊ธฐ, 11๊ฐ• ๊ฒฐ๊ณผ ํ–‰ ์ œํ•œํ•˜๊ธฐ - LIMIT, 12๊ฐ• ์ˆ˜์น˜ ์—ฐ์‚ฐ, 13๊ฐ• ๋ฌธ์ž์—ด ์—ฐ์‚ฐ, 14๊ฐ• ๋‚ ์งœ ์—ฐ์‚ฐ, 15 CASE ๋ฌธ์œผ๋กœ ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜ํ•˜..  (1) 2023.03.14
[51] 230313 SQL Ch. 2 ํ…Œ์ด๋ธ”์—์„œ ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰: 4๊ฐ• Hello World ์‹คํ–‰ํ•˜๊ธฐ, 5๊ฐ• ํ…Œ์ด๋ธ” ๊ตฌ์กฐ ์ฐธ์กฐํ•˜๊ธฐ, 6๊ฐ• ๊ฒ€์ƒ‰ ์กฐ๊ฑด ์ง€์ •ํ•˜๊ธฐ, 7๊ฐ• ์กฐ๊ฑด ์กฐํ•ฉํ•˜๊ธฐ, 8๊ฐ• ํŒจํ„ด ๋งค์นญ์— ์˜ํ•œ ๊ฒ€์ƒ‰ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 51์ผ]  (0) 2023.03.13
[50] 230310 SQL Ch. 6 ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ SQL: 25๊ฐ• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ฐ์ฒด, 26๊ฐ• ํ…Œ์ด๋ธ” ์ž‘์„ฑ, ์‚ญ์ œ, ๋ณ€๊ฒฝ, 27๊ฐ• ์ œ์•ฝ, 28๊ฐ• ์ธ๋ฑ์Šค ๊ตฌ์กฐ, 29๊ฐ• ์ธ๋ฑ์Šค ์ž‘์„ฑ๊ณผ ์‚ญ์ œ, 30๊ฐ• ๋ทฐ ์ž‘์„ฑ๊ณผ ์‚ญ์ œ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 50์ผ]  (0) 2023.03.10
Comments