查看完整内容
CREATE VIEW SchoolVolunteerCounts AS
SELECT
s.学校名称,
(SELECT COUNT(*) FROM 学生志愿表 WHERE 志愿1 = s.学校名称) AS 志愿1人数,
(SELECT COUNT(*) FROM 学生志愿表 WHERE 志愿2 = s.学校名称) AS 志愿2人数,
(SELECT COUNT(*) FROM 学生志愿表 WHERE 志愿3 = s.学校名称) AS 志愿3人数
FROM
学校表 s
ORDER BY
s.学校名称;