我正在编写一个select查询,在where条件中我想检查一个字段值,如果它是null,那么我只会其他其他字段值。请注意,select用于光标。
原始查询:
SELECT ni.node_installation_id,ni.customer_node_id,ni.customer_id,c.brand_name_1,substr(nitr.name,1,instr(nitr.name, ' ')-1) as node_inst_type
from node_installation ni , customer c , node_inst_type_release nitr
where ni.customer_id = c.customer_id
and ni.node_inst_type_release_id = nitr.node_inst_type_release_id
**and trunc(sysdate) - trunc(ni.arne_timestamp) >= 60**
and ni.no_of_collection_node_missed >= 4
and c.customer_id =90;
以粗体显示语句,如果ni.arne_timestamp为null,则结果也为null。在这种情况下,我想检查其他条件,如ni.arne_flag ='I',并在select查询中获取这些行。希望这次我很清楚。
答案 0 :(得分:1)
如果ni.arne_timestamp为null,则结果也为null。在这种情况下我想要 检查其他条件,如ni.arne_flag ='I'
在NULL
谓词中添加对AND
谓词的检查,如下所示:
...
AND(ni.arne_timestamp IS NULL OR ni.arne_flag = 'I')
AND(ni.arne_timestamp IS NULL
OR
(trunc(sysdate) - trunc(ni.arne_timestamp)) >= 60 )
因此,您的查询在此之后使用ANSI-92 JOIN
语法应如下所示:
SELECT
ni.node_installation_id,
ni.customer_node_id,
ni.customer_id,
c.brand_name_1,
substr(nitr.name, 1, instr(nitr.name, ' ') - 1) as node_inst_type
FROM node_installation ni
INNER JOIN customer c ON ni.customer_id = c.customer_id
INNER JOIN node_inst_type_release nitr
ON ni.node_inst_type_release_id = nitr.node_inst_type_release_id
WHERE (ni.arne_timestamp IS NULL OR ni.arne_flag = 'I')
AND (ni.arne_timestamp IS NULL
OR
(trunc(sysdate) - trunc(ni.arne_timestamp)) >= 60 )
AND ni.no_of_collection_node_missed >= 4
AND c.customer_id = 90;