SQL 服务器查询,在 select 语句中包含多个 INNER JOINS
SQL Server query with case in select statement with multiple INNER JOINS
我要查询 returns 一组关于项目的数据。然而,问题是某些项目没有有效的货币 ID。
所以我正在尝试构建一个查询,如果货币 ID 为 0,则使用 ID 140 代替。这是我目前所拥有的,但是 returns 如果货币 ID 为 0,则没有结果。
SELECT *,
CASE
WHEN p.currencyid=0 THEN 140
END
FROM projects AS p
INNER JOIN businesssectors AS bs ON bs.businesssectorid=p.businesssectorid
INNER JOIN currencies AS c ON c.currencyid=p.currencyid
INNER JOIN plants AS pl ON p.plantid=pl.plantid
WHERE p.projectid='195'
试试这个,它应该有效
SELECT *,
CASE
WHEN p.currencyid=0 THEN 140 ELSE p.currencyid
END
FROM projects AS p
INNER JOIN businesssectors AS bs ON bs.businesssectorid=p.businesssectorid
INNER JOIN plants AS pl ON p.plantid=pl.plantid
LEFT OUTER JOIN currencies AS c ON c.currencyid=p.currencyid
WHERE p.projectid='195'
我要查询 returns 一组关于项目的数据。然而,问题是某些项目没有有效的货币 ID。
所以我正在尝试构建一个查询,如果货币 ID 为 0,则使用 ID 140 代替。这是我目前所拥有的,但是 returns 如果货币 ID 为 0,则没有结果。
SELECT *,
CASE
WHEN p.currencyid=0 THEN 140
END
FROM projects AS p
INNER JOIN businesssectors AS bs ON bs.businesssectorid=p.businesssectorid
INNER JOIN currencies AS c ON c.currencyid=p.currencyid
INNER JOIN plants AS pl ON p.plantid=pl.plantid
WHERE p.projectid='195'
试试这个,它应该有效
SELECT *,
CASE
WHEN p.currencyid=0 THEN 140 ELSE p.currencyid
END
FROM projects AS p
INNER JOIN businesssectors AS bs ON bs.businesssectorid=p.businesssectorid
INNER JOIN plants AS pl ON p.plantid=pl.plantid
LEFT OUTER JOIN currencies AS c ON c.currencyid=p.currencyid
WHERE p.projectid='195'