tb_department 테이블 조회
select * from tb_department;
tb_student 테이블 조회
select * from tb_student;
SELECT
d.department_name,
a.*
FROM
(
SELECT
department_no,
COUNT(student_no) count
FROM
tb_student
GROUP BY
department_no
) a,
tb_department d
WHERE
a.department_no = d.department_no
ORDER BY
count DESC;
select * from departments;
select * from employees
select 하고자 하는 department_id, department_name 은 group_by 로 묶어준다.
SELECT
d.department_id,
d.department_name,
SUM(e.salary) salary
FROM
employees e,
departments d
WHERE
e.department_id = d.department_id
GROUP BY
d.department_id,
d.department_name;
'스터디 > Oracle' 카테고리의 다른 글
[Oracle] NVL, NVL2, NULLIF, DECODE, COALESCE, CASE WHEN (0) | 2023.06.20 |
---|---|
[Oracle / 오라클] 집합 연산자 UNION, UNION ALL, MINUS, INTERSECT (0) | 2023.06.19 |
[Oracle/오라클] LEAD() 다음 레코드 값, LAG() 이전 레코드 값 조회 (0) | 2021.10.19 |
[Oracle/오라클] FIRST_VALUE() 필드의 첫번째 값, LAST_VALUE() 마지막 값 구하기 (0) | 2021.10.19 |
[오라클/Oracle] INSTER, SUBSTR, REPLACE (0) | 2021.09.18 |