首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

求一SQL语句解决方案

2012-03-16 
求一SQL语句表如下:IDDATE1001110010001210010002310024100200015四位一个标识.来做计算即10010001 ,10010

求一SQL语句
表如下:
ID DATE
1001 1
10010001 2
10010002 3
1002 4
10020001 5

四位一个标识.来做计算
即10010001 ,10010002 为1001的子
10020001 为1002的子

现想把date字段中的值一个主的所有子的值加到主值中.应怎么样写SQL
结果应如下
ID DATE
1001 6
10010001 2
10010002 3
1002 9
10020001 5


[解决办法]

update table set date= d.counts from table c,
(select date,(select sum(date)from table b where charindex( a.identifier,b.identifier)>0)As counts from table a)d
where d.identifier = c.identifier

热点排行