Is not null 不消除空值
Is not null not eliminating nulls
有人可以帮助并阐明为什么我仍然得到空值,即使 table 连接中的条件之一指定替代单位不能为空值。
SELECT DISTINCT
CASE when oplistm.unit_code = 'CASE' then ROUND(oplistm.price / conv_factor,2)
when oplistm.unit_code = 'KG' then ROUND(oplistm.price * conv_factor,2)
WHEN oplistm.unit_code = 'EACH' and stu.converted_unit = 'KG' and stu.converted_unit is not null then ROUND(oplistm.price / conv_factor,2)
WHEN oplistm.unit_code = 'EACH' and stu.converted_unit = 'CASE' and stu.converted_unit is not null then ROUND(oplistm.price * conv_factor,2)
end as 'alternative unit price',
stu.converted_unit as 'alternative unit'
FROM sys030.scheme.oplistm oplistm (nolock)
left join sys030.scheme.stockm stockm (nolock) on stockm.product = oplistm.product_code
LEFT join sys030.scheme.stunitpm as stu (nolock) on stu.product = oplistm.product_code and stockm.warehouse = stu.warehouse and stu.base_name = stockm.unit_code and stu.converted_unit is not null
WHERE oplistm.product_code <>'LIC' and oplistm.product_code <> '' and stockm.product = 'M-47-68-BR-02-XX'
你在外连接的 on
子句中有这个条件:
stu.converted_unit is not null
虽然它确实过滤掉了 converted_unit
值 NULL
,但 LEFT JOIN
可能只是将它们添加回去。
因此,如果您确实需要此条件,请将 LEFT JOIN
更改为 INNER JOIN
。由于 WHERE
子句,第一个实际上是 INNER JOIN
。
有人可以帮助并阐明为什么我仍然得到空值,即使 table 连接中的条件之一指定替代单位不能为空值。
SELECT DISTINCT
CASE when oplistm.unit_code = 'CASE' then ROUND(oplistm.price / conv_factor,2)
when oplistm.unit_code = 'KG' then ROUND(oplistm.price * conv_factor,2)
WHEN oplistm.unit_code = 'EACH' and stu.converted_unit = 'KG' and stu.converted_unit is not null then ROUND(oplistm.price / conv_factor,2)
WHEN oplistm.unit_code = 'EACH' and stu.converted_unit = 'CASE' and stu.converted_unit is not null then ROUND(oplistm.price * conv_factor,2)
end as 'alternative unit price',
stu.converted_unit as 'alternative unit'
FROM sys030.scheme.oplistm oplistm (nolock)
left join sys030.scheme.stockm stockm (nolock) on stockm.product = oplistm.product_code
LEFT join sys030.scheme.stunitpm as stu (nolock) on stu.product = oplistm.product_code and stockm.warehouse = stu.warehouse and stu.base_name = stockm.unit_code and stu.converted_unit is not null
WHERE oplistm.product_code <>'LIC' and oplistm.product_code <> '' and stockm.product = 'M-47-68-BR-02-XX'
你在外连接的 on
子句中有这个条件:
stu.converted_unit is not null
虽然它确实过滤掉了 converted_unit
值 NULL
,但 LEFT JOIN
可能只是将它们添加回去。
因此,如果您确实需要此条件,请将 LEFT JOIN
更改为 INNER JOIN
。由于 WHERE
子句,第一个实际上是 INNER JOIN
。