tab
id city name price1 price2 price3
1 GD BB 0 0 0
2 GD CC 1 0 0
3 SZ DD 0 1 1
4 SZ EE 0 0 0现在要求 查出City为GD 和price1 price2 price3中价格有大于0的记录谢谢
id city name price1 price2 price3
1 GD BB 0 0 0
2 GD CC 1 0 0
3 SZ DD 0 1 1
4 SZ EE 0 0 0现在要求 查出City为GD 和price1 price2 price3中价格有大于0的记录谢谢
select * from tab where city='GD' and price1+price2+price3>0
where City = 'GD' and (price1 +price2 +price3) >0
from Tab
where City='GD' and (price1>0 or price2>0 or price3>0)
id city name price1 price2 price3
1 GD BB 0 0 0
2 GD CC 1 0 0
3 SZ DD 0 1 1
4 SZ EE 0 0 0现在要求 查出City为GD 和price1 price2 price3中价格有大于0的记录
select * from tab where city = 'GD' and (price1 > 0 or price2 >0 or price3 > 0)
create table #tab(id int,city varchar(5),name varchar(5),price1 int,price2 int,price3 int)
insert #tab(id,city,name,price1,price2,price3)
select '1','GD','BB','0','0','0' union all
select '2','GD','CC','1','0','0' union all
select '3','SZ','DD','0','1','1' union all
select '4','SZ','EE','0','0','0'
go
--执行测试语句
select t.id,t.city,t.name,t.price1,t.price2,t.price3 from #tab t
where City = 'GD' and (price1 +price2 +price3) >0go
--删除测试环境
drop table #tab
go
/*--测试结果
id city name price1 price2 price3
----------- ----- ----- ----------- ----------- -----------
2 GD CC 1 0 0(1 row(s) affected)
*/
如果有负数就麻烦了
Where City='GD'
And IsNull(Price1,0)+IsNull(Price2,0)+IsNull(Price3,0)>0
lz 是新手中的新手啊,
这个问题也放100。查出City为GD 和price1 price2 price3中价格有大于0的记录
是: City为GD 并且 price1 price2 price3中价格有大于0的记录 -------------1
还是 City为GD 或者 price1 price2 price3中价格有大于0的记录 -------------2前面的答案给出的是1。
如果要2 把第一个and 换成or
*
From
Tab
Where
City='GD' And (Price1>0 Or Price2>0 Or price3>0)
--------------------------------------------------------
楼上的都是正解。
lz 是新手中的新手啊,
这个问题也放100。-------------哈,看來你在CSDN是新手。樓主的帖子從來沒有少於100分的。
Select * From Table
Where City='GD'
And IsNull(Price1,0)+IsNull(Price2,0)+IsNull(Price3,0)>0
(
id int,
city nvarchar(20),
name nvarchar(20),
price1 int,
price2 int,
price3 int
)
insert into tabl
select 1,'GD','BB',0,1,0 union all
select 2,'GD','CC',1,0,0 union all
select 3,'SZ','DD',1,0,1 union all
select 4,'SZ','EE',1,1,0
select * from tabl where city='GD' and (price1>0 or price2>0 or price3>0)
drop table tabl
鱼记得这么清,下回人家没分,可不要不认真答
----------
你放心,樓主的馬甲有幾百個,從來沒有沒分的時候,每個帖子都是100分的。
Where City='GD'
And IsNull(Price1,0)+IsNull(Price2,0)+IsNull(Price3,0)>0whw123456() 存储过程比较好
select *
from Tab
where City='GD' and price1>0 and price2>0 and price3>0