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的记录谢谢

解决方案 »

  1.   

    --如:
    select * from tab where city='GD' and price1+price2+price3>0
      

  2.   

    select * from tablename
    where City = 'GD' and  (price1 +price2 +price3) >0
      

  3.   

    select *
    from Tab
    where City='GD' and (price1>0 or price2>0 or price3>0)
      

  4.   

    select * from tab where City='GD' and (price1>0 or price2>0  or price3>0 )
      

  5.   

    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)
      

  6.   

    ?Select * From tab Where City = 'GD' And (price1 >0 Or And price2 > 0 And price3 > 0)
      

  7.   

    --建立测试环境
    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)
    */
      

  8.   

    (price1 +price2 +price3) >0
    如果有负数就麻烦了
      

  9.   

    Select * From Table
     Where City='GD'
     And IsNull(Price1,0)+IsNull(Price2,0)+IsNull(Price3,0)>0
      

  10.   

    楼上的都是正解。
    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
      

  11.   

    Select 
          * 
    From 
          Tab 
    Where 
          City='GD' And (Price1>0 Or Price2>0 Or price3>0)
    --------------------------------------------------------
      

  12.   

    zahahui(zahahui) ( ) 信誉:100  2007-08-15 15:24:32  得分: 0  
     
     
       楼上的都是正解。
    lz 是新手中的新手啊,
    这个问题也放100。-------------哈,看來你在CSDN是新手。樓主的帖子從來沒有少於100分的。
      

  13.   

    应该是要找出查出City为GD并且price1 price2 price3中任意一个大于0的记录.
    Select * From Table
     Where City='GD'
     And IsNull(Price1,0)+IsNull(Price2,0)+IsNull(Price3,0)>0
      

  14.   

    create table tabl
    (
    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
      

  15.   

    wgzaaa() ( ) 信誉:100  2007-08-15 15:37:27  得分: 0  
     
     
       鱼记得这么清,下回人家没分,可不要不认真答
      
     
    ----------
    你放心,樓主的馬甲有幾百個,從來沒有沒分的時候,每個帖子都是100分的。
      

  16.   

    Select * From Table
     Where City='GD'
     And IsNull(Price1,0)+IsNull(Price2,0)+IsNull(Price3,0)>0whw123456() 存储过程比较好
      

  17.   

    要的是三个同时大于0吧:
    select *
    from Tab
    where City='GD' and price1>0 and price2>0 and price3>0