抱歉,如果事情真的很简单,我是个新手。我一直想把两张table合并起来,但做不成。正在尝试将雇员数添加到另一个表中。
SELECT [Training History].JobID,
(
SELECT Job.Department
FROM Job
WHERE [Training History].JobID = Job.JobID) AS Department,
SUM([Expenditure]) AS ExpenditureOfJob
FROM [Training History]
GROUP BY [Training History].JobID,
(
SELECT [Number of Employees]
FROM Q9r,
WHERE Q9r.JobID = [Training History].JobID
)
;
这使我在上一个select语句中出错(请帮助:)
q9r表格代码为;
SELECT JobID, COUNT (*) AS [Number of Employees] FROM Employee GROUP BY JobID;
enter code here
也不能让它工作(这是我比较喜欢的方式,因为它可以在一个表中完成)
SELECT [Training History].JobID,(
SELECT Job.Department
FROM Job
WHERE [Training History].JobID = Job.JobID)
AS Department,
SUM([Expenditure]) AS ExpenditureOfJob
FROM [Training History]
GROUP BY [Training History].JobID,
(SELECT COUNT (*) AS [Number of Employees]
FROM Employee
GROUP BY JobID)
;
这也不行
SELECT [Training History].JobID,(SELECT Job.Department FROM Job WHERE [Training History].JobID = Job.JobID) AS Department,
SUM([Expenditure]) AS ExpenditureOfJob FROM [Training History] GROUP BY [Training History].JobID,
(SELECT COUNT (*) AS [Number of Employees]
FROM Employee
WHERE [Training History].JobID = Employee.JobID
GROUP BY JobID)
;
2条答案
按热度按时间8ehkhllq1#
来自q9r,其中-->是未经请求的。
disho6za2#
您可以这样轻松地组合两个表:
顺便说一下,您的查询可以适应以下形式:
在任何情况下,我都把测试放在sql fiddle中