如:
select (t.num_1 + t.num_2) from table t
字段num_1有可能为null ,如果该条记录的num_1为空值,则用0和num_2相加。这个sql语句怎么写。
最好oracle和sql server的都写写。
在sql中
空值有NULL 和''的形式
当是NULL的时候用 IS NULL判断
当是''的时候用 =''判断
比如
select * from table where enddate IS NULL;
select * from table where str='';
空值有NULL 和''的形式
当是NULL的时候用 IS NULL判断
当是''的时候用 =''判断
比如
select * from table where enddate IS NULL;
select * from table where str='';
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-10-06
oracle:
select (nvl(t.num_1, 0)+t.num_2) from table t
sql server:
select (isnull(t.num_1, 0)+t.num_2) from table t本回答被提问者采纳
select (nvl(t.num_1, 0)+t.num_2) from table t
sql server:
select (isnull(t.num_1, 0)+t.num_2) from table t本回答被提问者采纳
第2个回答 2009-08-12
select (nvl(t.num_1, 0)+t.num_2) from table t
第3个回答 2009-08-12
用isnull方法判断为空不为空~
第4个回答 2009-08-12
<a href="">学习中</a>