原始数据能不能给改造成:
id,no,val
0,0,10
0,1,20
0,2,20
0,3,20
0,4,30
1,0,100
1,1,200
2,2,300
^
改这里这样就可以用case when
id,no,val
0,0,10
0,1,20
0,2,20
0,3,20
0,4,30
1,0,100
1,1,200
2,2,300
^
改这里这样就可以用case when
解决方案 »
- 关于两个表中的数据复制问题,用有A和B两个表,A中有AA列,B中有BB列,用update语句将BB列的前50条内容复制到AA列中的时候,为什么是同一条内容复制了50次?
- SQL 性能问题!!!
- 怎么实现把数据库中某表中某列的值定期导出成一个文件?
- 请问如何同步DataGrid与其它控件的内容?
- 两个用户同时执行select @@identity的问题
- 多个客户端同时读取一个表内的数据,怎样做到不重复取出数据
- ODBC远程连接SQL SERVER的问题
- 用户登录的程序,用存储进程来实现(SQL Server7)
- 身边实在没有资料。问一个菜问题:在SQLSERVER的存储过程中,定义了个Cursor。如何让它直接到末尾?我想取数据集的最后一条数据
- c语言调用函数求2到n之间的素数
- 配置发布服务器问题,在线等待!!
- 从别的机子copy过来的xxx_data.mdb,和xxx_log.ldf两个文件,怎么我的机器恢复???
from tableA a,(select val from tableA where id=1 and [no]=0) b where a.[id]=0
update table set percent =val/(select val from table where id=1 and no=2) where id=1 and (no=0 or no=1)
id,no,val
0,0,10
0,1,20
0,2,20
0,3,20
0,4,30
1,0,100
1,1,200
2,2,300CASE WHEN怎么用?
set percent =convert(numeric(10,2),val)/(select sum(val) from a where id=a1.id)
from a as a1
where id<>2or(for query,这里用到用CASE WHEN):select *,(case when id=2 then 0
else convert(numeric(10,2),val)/(select sum(val) from a where id=a1.id) end) as percent
from a as a1
from a as a1
select id,no,val,iif(id=2,0,val/(select sum(val) from a where id=a1.id)) as percent
from a as a1