如果 sql 中的值为 null,我需要使用默认值,条件如下。
SELECT sla.incident_generated_sla from eventedge_events_sla sla where e.client_id=sla.client_id and sla.priority_id=e.priority_id
我在下面使用了查询,但不起作用。
(SELECT sla.incident_generated_sla from eventedge_events_sla sla where e.client_id=sla.client_id and sla.priority_id=(IsNull(e.priority_id,"2")))
SELECT sla.incident_generated_sla from eventedge_events_sla sla
where e.client_id=sla.client_id and sla.priority_id=e.priority_id
(SELECT sla.incident_generated_sla from eventedge_events_sla sla
where e.client_id=sla.client_id and sla.priority_id=(IsNull(e.priority_id,"2")))
你几乎成功了。
检查此更正以自行尝试:
SELECT sla.incident_generated_sla from eventedge_events_sla sla
where e.client_id=sla.client_id and sla.priority_id=ISNULL(e.priority_id,2)
现在我不知道你的"e"是什么,但如果这是用你正在寻找的client_id声明的,它应该可以工作。
仔细看看我对你的ISNULL的更正。
编辑:评论后,这个答案是正确的;
SELECT
e.event_start_time,
sla.incident_generated_sla
FROM
eventedge_events_sla sla
left outer join eventedge_events e
ON e.client_id = sla.client_id
AND isnull(e.priority_id,2) = sla.priority_id
如果是MySQL,那就是IFNULL。
SELECT sla.incident_generated_sla
FROM eventedge_events_sla sla
LEFT JOIN eventedge_events e ON e.client_id = sla.client_id
WHERE sla.priority_id = IFNULL(e.priority_id,"2");