如何从案例语句Oracle SQL的结果集中排除null值行
我试图从单位_SHORTED列(来自案例子句)中排除具有null值的行,但找不到方法。
SELECT DISTINCT td.task_id,td.cntr_nbr,lh.dsp_locn AS pull_locn,td.orig_reqmt,td.qty_pulld,
(
CASE
WHEN
((SUM(td.qty_pulld) over (partition by td.pull_locn_id)) < td.orig_reqmt) and ((SUM(td.qty_pulld) over (partition by td.pull_locn_id))-td.orig_reqmt <> 0)
THEN (td.orig_reqmt- td.qty_pulld)
END) AS units_shorted
FROM wm14.task_dtl td
INNER JOIN wm14.locn_hdr lh ON lh.locn_id = td.pull_locn_id
INNER JOIN wm14.order_line_item oli ON oli.item_id = td.item_id
WHERE EXISTS (SELECT 1 FROM wm14.msg_log ml WHERE ml.user_id = td.user_id AND ml.msg_id IN ('1060','1034') AND module = 'CTRLKEY'
AND TRUNC(td.mod_date_time) = TRUNC(ml.create_date_time)) AND td.invn_need_type IN ('53','54')
AND td.stat_code >= '90'
and td.task_genrtn_ref_nbr NOT IN (SELECT ml.ref_value_1 FROM wm14.msg_log ml WHERE ml.msg ='Undo Wave completed')
group by td.task_id,td.cntr_nbr,lh.dsp_locn,td.task_genrtn_ref_nbr,td.pull_locn_id,td.item_id,td.qty_pulld,td.orig_reqmt
ORDER BY td.task_id,lh.dsp_locn DESC;
结果集:
TASK_ID, CNTR_NBR, PULL_LOCN, WAVE_NBR, ORIG_REQMT, QTY_PULLD, UNITS_SHORTED
5420174 GPK0324828 1GF-27-02144 202204200024 24 23 1
5420174 GPK0324822 1GF-23-03110 202204200024 5 3 2
5420174 GPK0324823 1GF-26-04102 202204200024 7 7 null
I am trying to exclude the rows with null values from Units_shorted column (from the CASE clause) but not finding a way.
SELECT DISTINCT td.task_id,td.cntr_nbr,lh.dsp_locn AS pull_locn,td.orig_reqmt,td.qty_pulld,
(
CASE
WHEN
((SUM(td.qty_pulld) over (partition by td.pull_locn_id)) < td.orig_reqmt) and ((SUM(td.qty_pulld) over (partition by td.pull_locn_id))-td.orig_reqmt <> 0)
THEN (td.orig_reqmt- td.qty_pulld)
END) AS units_shorted
FROM wm14.task_dtl td
INNER JOIN wm14.locn_hdr lh ON lh.locn_id = td.pull_locn_id
INNER JOIN wm14.order_line_item oli ON oli.item_id = td.item_id
WHERE EXISTS (SELECT 1 FROM wm14.msg_log ml WHERE ml.user_id = td.user_id AND ml.msg_id IN ('1060','1034') AND module = 'CTRLKEY'
AND TRUNC(td.mod_date_time) = TRUNC(ml.create_date_time)) AND td.invn_need_type IN ('53','54')
AND td.stat_code >= '90'
and td.task_genrtn_ref_nbr NOT IN (SELECT ml.ref_value_1 FROM wm14.msg_log ml WHERE ml.msg ='Undo Wave completed')
group by td.task_id,td.cntr_nbr,lh.dsp_locn,td.task_genrtn_ref_nbr,td.pull_locn_id,td.item_id,td.qty_pulld,td.orig_reqmt
ORDER BY td.task_id,lh.dsp_locn DESC;
Result set:
TASK_ID, CNTR_NBR, PULL_LOCN, WAVE_NBR, ORIG_REQMT, QTY_PULLD, UNITS_SHORTED
5420174 GPK0324828 1GF-27-02144 202204200024 24 23 1
5420174 GPK0324822 1GF-23-03110 202204200024 5 3 2
5420174 GPK0324823 1GF-26-04102 202204200024 7 7 null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个简单的选项 - 如果查询您有返回所需的结果集 - 是将其用作CTE(或子查询),然后滤除行:
A simple option - if query you have returns desired result set - is to use it as a CTE (or a subquery) and filter rows out: