|M| 求一句SQL查询语句
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的记录
谢谢
------解决方案----------------------如:
select * from tab where city= 'GD ' and price1+price2+price3> 0
------解决方案--------------------select * from tablename
where City = 'GD ' and (price1 +price2 +price3) > 0
------解决方案--------------------select *
from Tab
where City= 'GD ' and (price1> 0 or price2> 0 or price3> 0)
------解决方案--------------------select * from tab where City= 'GD ' and (price1> 0 or price2> 0 or price3> 0 )
------解决方案--------------------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的记录
select * from tab where city = 'GD ' and (price1 > 0 or price2 > 0 or price3 > 0)
------解决方案--------------------?
Select * From tab Where City = 'GD ' And (price1 > 0 Or And price2 > 0 And 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) > 0
go
--删除测试环境
drop table #tab
go
/*--测试结果
id city name price1 price2 price3
----------- ----- ----- ----------- ----------- -----------
2 GD CC 1 0 0
(1 row(s) affected)
*/
------解决方案--------------------