较复杂的赋值问题,急
create table test(id varchar(4),fen varchar(4), counter numeric(6,2),sign varchar(4))
insert into test
select '1','0',0,''
union all select '2','1',5,''
union all select '3','2',5.4,''
union all select '4','3',5.7,''
union all select '5','4',5.9,''
union all select '6','4',6.1,''
union all select '7','3',7.2,''
union all select '8','0',7.4,''
union all select '9','1',7.5,''
union all select '10','2',10,''
union all select '11','0',15,''
较复杂的赋值问题
赋值条件如下:选取min(counter), min(counter)+1内fen<>0的fen值, 如果sum(fen)>4,则min(counter)的fen值为4,其它数据的fen值为0,
如果sum(fen)<=4,每个数据的fen值不变,就这样循环计算
例如:
2 1 5.00
3 2 5.40
4 3 5.70
5 4 5.90
---------------
6 4 6.10
--------------
7 3 7.20
9 1 7.50
-------------
10 2 10.00
想得到的结果如下:
2 4 5.00
3 0 5.40
4 0 5.70
5 0 5.90
---------------
6 4 6.10
--------------
7 3 7.20
9 1 7.50
-------------
10 2 10.00
问题点数:50、回复次数:4Top
1 楼geniusqing(依帆)回复于 2005-08-01 18:04:00 得分 0
在线等Top
2 楼xzq111()回复于 2005-08-01 18:14:34 得分 0
将你的数据处理分几步来出来,利用中间表或临时表来存储中间结果Top
3 楼filebat(Mark)回复于 2005-08-01 23:50:34 得分 0
实在看不懂你想说什么。
你仔细解释一下吧。Top
4 楼operfume(橘子香水)回复于 2005-08-02 02:05:17 得分 50
create table test(id varchar(4),fen varchar(4), counter numeric(6,2),sign varchar(4))
insert into test
select '1','0',0,''
union all select '2','1',5,''
union all select '3','2',5.4,''
union all select '4','3',5.7,''
union all select '5','4',5.9,''
union all select '6','4',6.1,''
union all select '7','3',7.2,''
union all select '8','0',7.4,''
union all select '9','1',7.5,''
union all select '10','2',10,''
union all select '11','0',15,''
select *,idkey=FLOOR(counter) into #tmpTable1 from test where fen<>'0'
select id=min(id),fen=sum(convert(int,fen)),idkey
into #tmpTable2
from #tmpTable1 group by idkey
update #tmpTable1
set fen=case
when b.fen>4 then
case when a.id=b.id then 4 else 0 end
else a.fen
end
from #tmpTable1 a,#tmpTable2 b
where a.idkey=b.idkey
drop table #tmpTable2
select id,fen,counter from #tmpTable1
drop table #tmpTable1
drop table testTop




