我是CROSS JOIN
运营商解决的。
表L:
表R:
我的查询:
声明@userid int
设置@userid = null
SELECT T.Id, T.Name,T.UserId,R.Val
FROM
(
SELECT L.Id, L.Name,R.UserId
FROM
(SELECT DISTINCT UserId FROM R ) R
CROSS JOIN L
)T
LEFT OUTER JOIN R
ON (T.Id = R.DayId AND T.UserId = R.UserId)
where @userid is null or T.userid=@userid
结果: