(86번) average-time-of-process-per-machine
> 셀프 조인 활용에 대해서 배웠다.
Select a.machine_id , ROUND(avg(a.timestamp-b.timestamp),3) as "processing_time"
from Activity a JOIN Activity b
on a.machine_id = b.machine_id
and a.process_id = b.process_id
where 1=1
and b.activity_type = 'start'
and a.activity_type = 'end'
group by a.machine_id;
(87번) employee-bonus
> null 값은 연산에서 제외된다는 점을 잊지 말기
select e.name, b.bonus
from employee e left join bonus b
on e.empid = b.empid
where 1=1
and b.bonus < 1000
or b.bonus is null
(88번) students-and-examinations
> 3중 조인에 대해서 이해
SELECT s.student_id,
s.student_name,
u.subject_name,
COUNT(e.subject_name) AS attended_exams
FROM Students s JOIN Subjects u
LEFT JOIN Examinations e ON s.student_id = e.student_id AND u.subject_name = e.subject_name
GROUP BY s.student_id, u.subject_name
ORDER BY s.student_id, u.subject_name;
'[스파르타코딩클럽]데이터분석 과정 > SQL' 카테고리의 다른 글
[SQL 코드카타] 92~94번 (LeetCode) (0) | 2024.01.04 |
---|---|
[SQL 코드카다] 89~92번 (LeetCode) (0) | 2024.01.03 |
[SQL][개인과제] ECOMMERCE 데이터 분석(2)_중급~상급 문제 (1) | 2024.01.02 |
[SQL][개인과제] ECOMMERCE 데이터 분석(1)_세팅~초급 문제 (0) | 2024.01.02 |
[SQL] 순위 매기기 (0) | 2024.01.01 |