嗨,我有一个 SQL 服务器数据库,当我执行以下查询时,我得到 4 个结果:
WITH MyCTE (ID, hasLead, SubgroupFk, SubTeamFk)
AS (
SELECT [ID],[hasLead],[SubgroupFk],[SubTeamFk]
FROM [LocalGTPDatabase].[dbo].[LinkProject-Area]
where [ProjectFk]=90
)
SELECT
*
FROM MyCTE
INNER JOIN EmplTeam ON EmplTeam.ID = MyCTE.SubTeamFk
INNER JOIN [Department] ON [Department].ID = MyCTE.SubgroupFk
对于每个 LinkProjectArea Id,我有 1 个 Headcount 项目/年
Headcount 表连接到:LinkProjectAreaFk 到前面提到的表
所以我想我可以将人数与以下查询结合起来:
WITH MyCTE (ID, hasLead, SubgroupFk, SubTeamFk)
AS (
SELECT [ID],[hasLead],[SubgroupFk],[SubTeamFk]
FROM [LocalGTPDatabase].[dbo].[LinkProject-Area]
where [ProjectFk]=90
)
SELECT
*
FROM MyCTE
INNER JOIN EmplTeam ON EmplTeam.ID = MyCTE.SubTeamFk
INNER JOIN [Department] ON [Department].ID = MyCTE.SubgroupFk
INNER JOIN [HeadCount] ON [HeadCount].LinkProjectAreaFk = MyCTE.ID
但是当我执行这个查询时,我没有得到任何结果,但是这个查询的每个 id 都有一个人数。我究竟做错了什么?
我真的不知道