我使用带NVL
的简单SQL,但查询未正确显示结果。我的要求是,如果Shipment_refnum_qual_gid
是' ULA / SAO.UL_ONU'然后获取此refnum
的值,否则在结果中显示NULL
。
示例查询如下。
SELECT NVL (SRF.SHIPMENT_REFNUM_VALUE, 'NULL')
FROM SHIPMENT_REFNUM SRF, SHIPMENT SH
WHERE SRF.SHIPMENT_GID= SH.SHIPMENT_GID AND SH.SHIPMENT_GID = 'ULA/SAO.5000057288'
AND SRF.SHIPMENT_REFNUM_QUAL_GID = 'ULA/SAO.UL_ONU
答案 0 :(得分:0)
MySQL没有NVL
功能。相反,请使用IFNULL
:
select ifnull(SRF.SHIPMENT_REFNUM_VALUE, 'NULL')
from SHIPMENT_REFNUM SRF, SHIPMENT SH
where SRF.SHIPMENT_GID= SH.SHIPMENT_GID
and SH.SHIPMENT_GID = 'ULA/SAO.5000057288'
and SRF.SHIPMENT_REFNUM_QUAL_GID = 'ULA/SAO.UL_ONU'
修改强>
正如您在评论中所说,SHIPMENT_REFNUM
中的SHIPMENT
中的一个或多个值中没有匹配的条目,但是您希望包含这些条目,您需要一个外部联接:< / p>
select ifnull(SRF.SHIPMENT_REFNUM_VALUE, 'NULL')
from SHIPMENT_REFNUM SRF
right outer join SHIPMENT SH on SRF.SHIPMENT_GID= SH.SHIPMENT_GID
where SH.SHIPMENT_GID = 'ULA/SAO.5000057288'
and SRF.SHIPMENT_REFNUM_QUAL_GID = 'ULA/SAO.UL_ONU'