題組內容

二、假設現有如下會議室借用紀錄資訊的關連式資料庫,請使用 SQL 回答相 關的子問題。 Room(rID, type, capacity, manageDept) FKs: manageDept ref. Department(dID) Department(dID, name, managerID) FKs: managerID ref. Employee(eID) Employee(eID, name, deptID, expertise) FKs: deptID ref. Department(dID) UseRecord(roomID, employeeID, date, startHour, endHour, purpose) FKs: roomID ref. Room(rID), employeeID ref. Employee(eID) 其中 eID 是由西元年+3 位數的流水號所組成,如 2019001 表示 2019 年 第一位公司所聘用的員工。部門的主管,不一定是該部門的員工。所有 資料欄位不允許空白。

⑶請列出 2018 年各種不同功能類型且人數容量大於 10 的會議室,被 借用的次數,並依借用次數的多寡降冪排序。 (5 分)

詳解 (共 1 筆)

詳解 提供者:Allison
SELECT r.type, COUNT(*) AS 借用次數
FROM Room r, UseRecord u
WHERE r.rID = u.roomID
  AND u.date >= '2018-01-01'
  AND u.date < '2019-01-01'
  AND r.capacity > 10
GROUP BY r.type
ORDER BY COUNT(*) DESC;