Schema & Query Design

이정민·2021년 12월 16일

schema는 데이터베이스에서 데이터가 구성되는 방식과 서로 다른 엔티티간의 관계에 대한 설명
=> 데이터 베이스의 청사진

ex. 수강신청 데이터베이스
entity - teachers
             classes
             students
fields - name/ department/classes 교사에게는 이름, 부서, 그리고 맡고 있는 수업목록 column(열)
             name/room number/ teacher /students
             Name, email, classes
record: Cynthia/ Music/ Music Theory, brass Methods row(행)
=> Music Theory, brass Methods를 가르치는 music department의 Cynthia 선생님

SELECT CustomerId, AVG(Total)
FROM invoices
WHERE CustomerId >= 10
GROUP BY CustomerId
HAVING SUM(Total) >= 30
ORDER BY 2

=>
1. FROM invoices: invoices 테이블에 접근을 합니다.
2. WHERE CustomerId >= 10: CustomerId 필드가 10 이상인 레코드들을 조회합니다.
3. GROUP BY CustomerId: CustomerId를 기준으로 그룹화합니다.
4. HAVING SUM(Total) >= 30: Total 필드의 총합이 30 이상인 결과들만 필터링합니다.
5. SELECT CustomerId, AVG(Total): 조회된 결과에서 CustomerId 필드와 Total 필드의 평균값을 구합니다.
6. ORDER BY 2: AVG(Total) 필드를 기준으로 오름차순 정렬한 결과를 리턴합니다.

0개의 댓글