我對SQL Server非常沮喪。我只是試圖加入3個表格,非常簡單,並且很容易在mysql中完成。但在SQL Server中,它一直告訴我在集合函數中包含tbl_department.deptname
。但是,我可能在一個簡單的字符串中使用什麼聚合函數?SQL Server中的聚合函數
SELECT
COUNT(tblStudent_Department.student_id) AS Expr2,
tbl_department.deptname AS Expr1
FROM
tblStudent_Department
LEFT OUTER JOIN
tbl_department ON tblStudent_Department.deptcode = tbl_department.deptcode
LEFT OUTER JOIN
tblStudent ON tblStudent_Department.student_id = tblStudent.studentid
GROUP BY
tblStudent_Department.deptcode
請幫忙。
我上次檢查時,SQL Server不支持'first()'或'last()'聚合?這不是Oracle/Postgres嗎? – Andomar 2012-03-04 13:29:18