如何连接这两个表以根据部门名称和周数连接数据。因此,如果周数不匹配,则显示其他人的空值。
答案 0 :(得分:1)
完整的外连接应该可以解决问题:
SELECT d.id,
d.name,
f.id,
DATEPART(WEEK, setupdate) as WeekNumber
FROM departments d
FULL OUTER JOIN forecast f ON d.name = f.name AND
DATEPART(WEEK, setupdate) = DATEPART(WEEK, forecast)