表里有两字段,
毛利润 mlr
预期利润 yqlr
这2个字段有一个字段是肯定有值的,
但是不知道是哪个有值,所以查询利润的时候,如果毛利润为空就查询预期利润,如果预期利润为空就查询毛利润,
这个有判断的查询语句怎样写?
首先要确保这里的 空值 是 NULL,还是0,或是''。
如果是NULL,则:
select NVL(mlr,yqlr) as result from table_name
select NVL2(mlr,mlr,yqlr) as result from table_name (9i及之后)
如果是0:
select NVL(NULLIF(mlr,0),yqlr) as result from table_name (9i及之后)
如果是'',可以参照上面处理
如果是其它情况的话,可能还要转换判断一下!
以上仅参考!
如果是NULL,则:
select NVL(mlr,yqlr) as result from table_name
select NVL2(mlr,mlr,yqlr) as result from table_name (9i及之后)
如果是0:
select NVL(NULLIF(mlr,0),yqlr) as result from table_name (9i及之后)
如果是'',可以参照上面处理
如果是其它情况的话,可能还要转换判断一下!
以上仅参考!
温馨提示:答案为网友推荐,仅供参考
第1个回答 2009-05-05
select mlr from 表名 where yqlr is NULL;
select yqlr from 表名 where mlr is NULL;
select yqlr from 表名 where mlr is NULL;
第2个回答 2009-05-05
select mlr from 表名 where yqlr is NULL;
select yqlr from 表名 where mlr is NULL
select yqlr from 表名 where mlr is NULL