SELECT Student.S_ID, COUNT(*) AS **Final_Exam_Level**
FROM Student, Exams, Exam_Allocation
WHERE (Student.S_ID)=Exam_Allocation.S_ID
And ((Exams.Exam_ID)=Exam_Allocation.Exam_ID)
And (Exams.Date_Taken) <= #12/31/2010#
GROUP BY Student.S_ID, Student.Course_Level
ORDER BY Student.S_ID;
SELECT Student.S_ID AS S_ID, Student.First_Name AS First_Name, Student.Surname AS Surname, MAX(New_Models.Date_Issued) AS Last_Course_Date, MAX(New_Models.Issue) AS Last_Issue, MAX(New_Models.Model_ID) AS Last_Model_ID, Student.Course_Level AS No_Training_Courses
FROM New_Models, New_Models_Allocation, Student
WHERE New_Models.Model_ID=New_models_Allocation.Model_ID And Student.S_ID=New_Models_Allocation.S_ID
GROUP BY Student.S_ID, Student.Course_Level, First_Name, Surname
ORDER BY MAX(New_Models.Model_ID) DESC;
如何添加Final_Exam_Level到第二個查詢?合併兩個SQL查詢
Final_Exam_Level正在統計每個學生做了多少個Exam_ID。 Exam_Allocation有兩個外鍵,S_ID和Exam_ID
select Query_New_Models.*, Query_Exam.Final_Exam_Level
FROM (SELECT Student.S_ID AS S_ID, Student.First_Name AS First_Name, Student.Surname AS Surname, MAX(New_Models.Date_Issued) AS Last_Course_Date, MAX(New_Models.Issue) AS Last_Issue, MAX(New_Models.Model_ID) AS Last_Model_ID, Student.Course_Level AS No_Training_Courses
FROM New_Models, New_Models_Allocation, Student
WHERE New_Models.Model_ID=New_models_Allocation.Model_ID And Student.S_ID=New_Models_Allocation.S_ID
GROUP BY Student.S_ID, Student.Course_Level
ORDER BY MAX(New_Models.Model_ID) DESC) INNER JOIN (SELECT Student.S_ID, COUNT(*) AS Final_Exam_Level
FROM Student, Exams, Exam_Allocation
WHERE (Student.S_ID)=Exam_Allocation.S_ID
And ((Exams.Exam_ID)=Exam_Allocation.Exam_ID)
And (Exams.Date_Taken)<=#12/31/2010#
GROUP BY Student.S_ID, Student.Course_Level
ORDER BY Student.S_ID
) ON Query_Exam.S_ID = Query_New_Models.S_ID ;
對不起的子查詢,但這些查詢返回一個(非常)不同的列數。 ..那麼你怎麼能融合他們? – Marco 2011-05-02 21:00:20
如果您陳述您想要實現什麼目標,可能會更容易,除了「合併這兩個查詢」。結果數據集應該是什麼樣子? – FrustratedWithFormsDesigner 2011-05-02 21:03:01
我想添加一列到另一列。儘管如此,他們擁有相同的編號或記錄。他們都展示了技術人員的詳細信息 – Qatrelnada 2011-05-02 21:03:44