s****e 发帖数: 1180 | 1 借宝地问个面试中的sql的问题。
We have two tables, students (student ID, student name, student age, student
zip) and courses (course name, course time) .
The information in the parentheses are the schema.
We want to get how many students enroll all the classes starting at 11:00 AM?
the interviewer mentioned something like many to many join.
the interviewer mentioned something like "dimensionalize" in SQL. I am
wondering who knows any SQL book on this, and can introduce it me?
Thank you so much for your consideration! | s****e 发帖数: 1180 | 2 借宝地问个面试中的sql的问题。
We have two tables, students (student ID, student name, student age, student
zip) and courses (course name, course time) .
The information in the parentheses are the schema.
We want to get how many students enroll all the classes starting at 11:00 AM?
the interviewer mentioned something like many to many join.
the interviewer mentioned something like "dimensionalize" in SQL. I am
wondering who knows any SQL book on this, and can introduce it me?
Thank you so much for your consideration! | m***c 发帖数: 257 | 3 缺个表记录students 和 courses的对应关系(M to N)
enroll(studentID, coursename, enrolltime)
primary key(studentID, course name, enroll time)
foreign key(studentID) references students(studentID)
foreign key(coursename) form students(coursename)
SELECT S.studentID, S.studentname
FROM students AS S INNER JOIN enroll AS E ON S.studentID= E.studentID
GROUP BY S.studentID, S.studentname
HAVING COUNT(*) = (SELECT COUNT(*) FROM courses)
看《数据库系统导论》吧 |
|