当前位置: 代码迷 >> Sql Server >> 简单的查询,该如何解决
  详细解决方案

简单的查询,该如何解决

热度:8   发布时间:2016-04-27 17:26:29.0
简单的查询
现有一个表table1:
BH           SL             ZL
A1           1               1.2
A2           0                 0
A3           1                 0
A4           0                 1
A5           2                 10

现在想把SL和ZL都等于0的数据过滤了,查询出的数据如下:
BH           SL             ZL
A1           1               1.2
A3           1                 0
A4           0                 1
A5           2                 10

SQL语句咱写呢?谢谢(在线等)

                 



------解决方案--------------------
---例子
create table table1(BH varchar(10), SL int, ZL int)
insert table1
select 'A1 ', 1 , 1.2
union select 'A2 ', 0 , 0
union select 'A3 ', 1 , 0
union select 'A4 ', 0 , 1
union select 'A5 ', 2 , 10

select * from table1 where (sl+zl) <> 0

drop table table1

/*
BH SL ZL
---------- ----------- -----------
A1 1 1
A3 1 0
A4 0 1
A5 2 10

(4 row(s) affected)
*/
------解决方案--------------------
如果SL和ZL没有负数的可能
select BH,SL,ZL from table1 where (sl+zl) > 0

  相关解决方案