SQL> with test (prod_nm, jan, feb, mar, apr) as
2 (select 'GRANULES' , 500, 200, 100, 500 from dual union all
3 select 'INJECTION', 0, 0, 300, 550 from dual union all
4 select 'VET-A' , 0, 0, 0, 300 from dual union all
5 select 'VET-B' , 0, 0, 0, 0 from dual
6 )
查询:
7 select *
8 from test
9 where jan <> 0 or feb <> 0 or mar <> 0 or apr <> 0;
PROD_NM JAN FEB MAR APR
--------- ---------- ---------- ---------- ----------
GRANULES 500 200 100 500
INJECTION 0 0 300 550
VET-A 0 0 0 300
SQL>
with test (prod_nm, jan, feb, mar, apr) as
(select 'GRANULES' , 500, 200, 100, 500 from dual union all
select 'INJECTION', 0, 0, 300, 550 from dual union all
select 'VET-A' , 0, 0, 0, 300 from dual union all
select 'VET-B' , 0, 0, 0, 0 from dual
)
select *
from test
where 0 < any (jan, feb, mar, apr);
PROD_NM JAN FEB MAR APR
--------- ---------- ---------- ---------- ----------
GRANULES 500 200 100 500
INJECTION 0 0 300 550
VET-A 0 0 0 300
SQL>
3条答案
按热度按时间eyh26e7m1#
如果受影响的列总是自然数,您可以对它们求和,并检查它们是否〉0。
如果它们可以是负数,但始终是数字,则可以基于它们的绝对值执行相同的操作。
5jvtdoz22#
在真实的情况中,您只需在
where
子句中放入更多列。示例数据:
查询:
py49o6xq3#
使用where + any: