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
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
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
这语法就有问题着呢,
最好给出你的测试数据和你需要的结果。
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
请问这样的功能怎么加条件。 或者说要用游标?
如果是的话它在什么时候更新?是随基本表更新吗?还是其他什么时候更新
--> 数据库版本:
--> 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修改数据的时候,视图索引也自动维护了,不用你管。
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