我试图像这样左右加入3个表:
DECLARE @CustomerID AS INT;
DECLARE @ProductID AS INT;
SELECT *
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.id
LEFT JOIN table3 t3 ON t2.loc = t3.loc
WHERE t1.id = @ProductID
AND (t2.loc = t3.loc OR t2.loc IS NULL)
AND (t3.cid = @CustomerID OR t3.cid IS NULL)
我试图解决4个基本案例:
上面的代码适用于案例1-3,但在案例4中没有返回任何内容。我认为这是因为最后一次LEFT JOIN中断(即使t1和t2中的数据都存在于@ProductID中)。 / p>
有没有办法在不使用IF ... ELSE逻辑的情况下使第二个LEFT JOIN成为条件?
答案 0 :(得分:2)
将条件放在on
子句而不是where
子句
SELECT *
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.id
LEFT JOIN table3 t3 ON t2.loc = t3.loc
AND (t3.cid = @CustomerID OR t3.cid IS NULL)
AND (t2.loc = t3.loc OR t2.loc IS NULL)
WHERE t1.id = @ProductID
答案 1 :(得分:0)
如果我理解你想要的东西,这可能有效:
<Directory /var/www/xxx>
Require all granted
</Directory>