我想计算出借书数量最多的学科领域。我有以下查询:
SELECT SubjectArea
FROM (
SELECT SubjectArea, MAX( Copies_On_Loan ) AS Max
FROM (
SELECT
Section.SubjectArea AS SubjectArea,
SUM( LoanBook.Copies_On_Loan ) AS Copies_On_Loan
FROM Section
NATURAL JOIN Items
NATURAL JOIN LoanBook
GROUP BY Section.SubjectArea
) AS Table1
) AS Table2
最里面的查询:
SELECT
Section.SubjectArea AS SubjectArea,
SUM( LoanBook.Copies_On_Loan ) AS Copies_On_Loan
FROM Section
NATURAL JOIN Items
NATURAL JOIN LoanBook
GROUP BY Section.SubjectArea
返回下表:
SubjectArea Copies_On_Loan
Biology 0
DBMS 3
但是,整个查询给出的结果是生物学(而不是 DBMS)。请提出为什么会这样