select riqi,max(id) as id if(name='aa')begin id='1000'end, 
cast(sum(zhitonglv)/max(NO1) as varchar(24))+'%' as gy if(gy='0')begin gy='1' end, 
from t_object_RIchan 
group by riqi
order by riqi desc

解决方案 »

  1.   

    select riqi,max(id) as id if(name='aa')begin id='1000'end, 
    cast(sum(zhitonglv)/max(NO1) as varchar(24))+'%' as gy if(gy='0')begin gy='1' end, 
    from t_object_RIchan 
    where ....  --怎么加,加什么,您自己搞明白。
    group by riqi
    order by riqi desc
      

  2.   

     if(name='aa')begin id='1000'end
    这语法就有问题着呢,
    最好给出你的测试数据和你需要的结果。
      

  3.   

    测试数据
    test
    C1   C2   C3   C4
    1    0    1     100
    2    0    0     98
    3    1    1     56
    4    1    0      58
    想要结果
    select c4 from test  条件 ifc2=’0‘ and c3=’0‘  c4=100
    test
    C1   C2   C3   C4
    1    0    1     100
    2    0    0     100
    3    1    1     56
    4    1    0      58
    请问这样的功能怎么加条件。  或者说要用游标?
      

  4.   

    顺便问下。SQL2000的索引视图是重新建了一张表吗、? 
    如果是的话它在什么时候更新?是随基本表更新吗?还是其他什么时候更新
      

  5.   


    --> 数据库版本:
    --> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
    --> 测试数据:test
    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'test') 
    AND type in (N'U')) 
    DROP TABLE test
    GO---->建表
    create table test([C1] int,[C2] int,[C3] int,[C4] int)
    insert test
    select 1,0,1,100 union all
    select 2,0,0,98 union all
    select 3,1,1,56 union all
    select 4,1,0,58
    GO--> 查询结果
    SELECT C1,C2,C3,case when C2='0' and C3='0' then 100 else  C4 end as C4
    FROM test
    --> 删除表格
    --DROP TABLE test修改数据的时候,视图索引也自动维护了,不用你管。
      

  6.   

    create table tt(c1 int,c2 int,c3 int,c4 int)
    insert tt
    select 1,0,1,100 union all
    select 2,0,0,98 union all
    select 3,1,1,56 union all
    select 4,1,0,58select c1,c2,c3,c4=case when c2=0 and c3=0 then 100 else c4 end from tt 
      

  7.   

    游标是按行来处理数据的,为了效率能不用就不要用。视图嘛:它是一个虚拟表,就是Select 的结果,如果谈到修改视图数据的话,你就把它当表也可以,简单的说就是修改视图也可以修改基表中的数据;不过要看视图的基表结构!