嗨,我正在爲下面的數據庫結構寫一個mysql查詢。mysql查詢不返回預期值
Professor (EMP ID,Name,Status,Salary,Age)
Course(Course ID,Course Name,Points)
Works(Course ID,EMP ID,Class ID)
Assumptions:
Each course has only one instructor in each semester
Status can take values from 「Full」, 「Associate」, and 「Assistant」
我需要執行以下操作。
返回誰教過至少兩個療程在一類
SELECT p.name
FROM professor p, works w
WHERE p.empid = w.empid
AND p.status = ‘full’
AND w.classid IN (SELECT classid
FROM works
WHERE count(courseid)>1)
誰教人數最多的課程在10
類的教授(或多個)歸來的姓名(或名稱)全職教授的名字SELECT p.names
FROM professor p, works w
WHERE p.empid =w.empid
AND w.classid IN (SELECT classid
FROM works
WHERE classid = 10
AND coursed = max(coursed))
但這些查詢返回錯誤的結果。我是新來的MySQL請幫忙。
你應該閱讀有關明確連接,GROUP BY和聚集。 – 2013-03-08 11:48:23