CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  应用实例

较复杂的赋值问题,急

楼主geniusqing(依帆)2005-08-01 17:26:24 在 MS-SQL Server / 应用实例 提问

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

相关问题

  • 较复杂的赋值问题,急 ,在线等
  • 赋值问题,急!!
  • 急!!!数组赋值
  • unsigned short赋值!!!急
  • 赋值与比较后赋值哪种性能更好?
  • 字段赋值问题!!很急~~~~
  • 怎样给RTF文本域赋值?急!!!
  • 查询赋值的问题, 急!!
  • 如何对html控件赋值!(急!!!)
  • 急啊!!这个怎么赋值???

关键词

  • fen
  • tmptable
  • 赋值
  • counter
  • 值
  • union all select
  • min
  • sum
  • varchar
  • table

得分解答快速导航

  • 帖主:geniusqing
  • operfume

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo