首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单的查询,该如何解决

2012-02-29 
简单的查询现有一个表table1:BHSLZLA111.2A200A310A401A5210现在想把SL和ZL都等于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

热点排行