ComputerScience/Database(5)
-
[Database] SQL Assignment 6
#1 SELECT last_name, hire_date FROM employees WHERE department_id in ( SELECT department_id FROM employees WHERE last_name = 'Zlotkey' ) AND last_name 'Zlotkey'; subquery ์์ด join์ผ๋ก ํํํ๊ธฐ SELECT D.last_name, D.hire_date FROM employees E, employees D WHERE E.department_id = D.department_id AND E.last_name = 'Zlotkey' AND D.last_name 'Zlotkey' #2 SELECT employee_id, last_name FROM employees WHERE sa..
2024.04.19 -
[Database] SQL Assignment 5
#1 SELECT MAX(salary) "Maximum", MIN(salary) "Minimum", SUM(salary) "Sum", AVG(salary) "Average" FROM employees #2 SELECT job_id, MAX(salary) "Maximum", MIN(salary) "Minimum", SUM(salary) "Sum", AVG(salary) "Average" FROM employees GROUP BY job_id #3 SELECT job_id, COUNT(employee_id) FROM employees GROUP BY job_id -- COUNT(*) : ๊ฐ ๊ทธ๋ฃน์ ํฌํ ์๋ฅผ count #4 SELECT COUNT(COUNT(MANAGER_ID)) "Number of mana..
2024.04.19 -
[Database] SQL Assignment 4
#1. SELECT last_name, department_id, department_name FROM employees NATURAL JOIN departments -- department_id๊ฐ ๋์ผํ๊ธฐ ๋๋ฌธ์ NATURAL JOIN (32๊ฐ) -> ํ๋๋ฅผ ์์ ๋ฒ๋ฆฐ๋ค. -- But departments_id ๋ฟ๋ง ์๋๋ผ, manager_id๊ฐ ๊ฐ๊ธฐ ๋๋ฌธ์ (์๋ก ๋ค๋ฅธ ์๋ฏธ, ๋์ ์ฌ์ vs ๋ถ์์ฅ), natural join์ ํ๋ฉด ํ๋ฆผ select e.last_name, e.department_id, d.department_name from employees e INNER JOIN departments d on (e.department_id = d.department_id) -- 106๊ฐ ๊ฐ์ด ๋ค๋ฅด๋ค..
2024.04.02 -
[Database] SQL Assignment 3
1. ํ์ฌ ๋ ์ง๋ฅผ ํ์ํ๋ ์ง์๋ฅผ ์์ฑํ๊ณ ์ด ๋ ์ด๋ธ์ Data๋ก ์ง์ ํ์ญ์์ค. SELECT sysdate as "Date" FROM DUAL -- from ์ ์ ๊ผญ ์จ์ผ ํ๋๊น, dummy table๋ก DUAL ์ ๊ณต 2. ๊ฐ ์ฌ์์ ๋ํด ์ฌ์ ๋ฒํธ, ์ด๋ฆ , ๊ธ์ฌ ๋ฐ 15% ์ธ์๋ ๊ธ์ฌ๋ฅผ ์ ์๋ก ํ์ํ์ญ์์ค. ์ธ์๋ ๊ธ์ฌ ์ด์ ๋ ์ด๋ธ์ New Salary ๋ก ์ง์ ํ์ญ์์ค. SELECT employee_id, last_name, salary, (salary * 1.15) AS "New Salary" FROM employees 3. ์ด๋ฆ์ด J, A๋๋ M์ผ๋ก ์์ํ๋ ๋ชจ๋ ์ฌ์์ ์ด๋ฆ(์ฒซ ๊ธ์๋ ๋๋ฌธ์๋ก, ๋๋จธ์ง ๊ธ์๋ ์๋ฌธ์๋ก ํ์) ๋ฐ ์ด๋ฆ ๊ธธ์ด๋ฅผ ํ์ํ๋ ์ง์๋ฅผ ์์ฑํ๊ณ ๊ฐ ์ด์ ์ ํฉํ ๋ ์ด๋ธ์ ์ง์ ..
2024.04.02 -
[Database] SQL Assignment 2
SQL: Restricting and Sorting Data 1. ๊ธ์ฌ๊ฐ $12,000๋ฅผ ๋๋ ์ฌ์์ ์ด๋ฆ๊ณผ ๊ธ์ฌ๋ฅผ ํ์ SELECT last_name, salary FROM employees WHERE salary >= 12000; 2. ์ฌ์ ๋ฒํธ๊ฐ 176์ธ ์ฌ์์ ์ด๋ฆ๊ณผ ๋ถ์ ๋ฒํธ๋ฅผ ํ์ SELECT last_name, department_id FROM employees WHERE employee_id = 176; 3. ๊ธ์ฌ๊ฐ $5,000์์ $12,000 ์ฌ์ด์ ํฌํจ๋์ง ์๋ ๋ชจ๋ ์ฌ์์ ์ด๋ฆ๊ณผ ๊ธ์ฌ๋ฅผ ํ์ SELECT last_name, salary FROM employees WHERE salary = 12000 4. 2007๋ 2์ 20์ผ๊ณผ 2007๋ 5์ 1์ผ ์ฌ์ด์ ์ ์ฌํ ์ฌ์์ ์ด๋ฆ, ์ ๋ฌด..
2024.04.01