update aa set number=50 where id=13; update aa set number=25 where id=1303;
更新完成后我如何用select sum(number).....得到如下的值(1301+1302+130301+130102)即底层结点的值--------------------- 你究竟是求和还是并ID?求和是用SELECT SUM(NUMBER) FROM AA 如果是想要得到你括号你的效果的话, 那么的用"||"来
有一个表aa 内容如下
id number 13 1301 10 1302 15 1303 130301 15 130302 10.....如何用SQL语句把 13跟1303记录的number值为50,25 select * from aa id number 13 50 1301 10 1302 15 1303 25 130301 15 130302 10 更新完成后我如何用select sum(number).....得到如下的值(1301+1302+130301+130102)即底层结点的值 number 50 是求和
1、先求select sum(number).....得到如下的值(1301+1302+130301+130102)即底层结点的值,也就是在没有更新之前,直接用 select sum(number) from a 即可。另外130301+130302的值跟1303的值不一样吗?1301+1302+130301+130102的值跟13的值不一样吗?楼主为什么要搞得这么复杂?2、从底层往上开始更新,也就是先更新1303级别的值,再更新13级别的值。 update a set number =(select sum(b.number) from a b where length(b.id)=length(a.id)+2 ) ;
你的意思是这样的吧,id=13的number值是所有id中前两位含有13的number的合计,id=1303的number值是所以id含有1303的number的合计吧update aa set number=(select sum(number) from aa where substr(to_char(id),1,2)='13') where id=13; update aa set number=(select sum(number) from aa where substr(to_char(id),1,4)='1303') where id=13;
update aa set number=(select sum(number) from aa where substr(to_char(id),1,4)='1303') where id=1303;
update aa a set number=(select sum(number) from aa b where a.id=substr(b.id,1,6)) where a.number=0 and length(a.id)=6update aa a set number=(select sum(number) from aa b where a.id=substr(b.id,1,4)) where a.number=0 and length(a.id)=4update aa a set number=(select sum(number) from aa b where a.id=substr(b.id,1,2)) where a.number=0 and length(a.id)=2
update aa a set number = select sum(number) from aa b where a.id = substr(b.id, 1, length(a.id)) where length(a.id) = X; (若最后子结点为10,X = 8,为8,X = 6,.....) 只能从最后子结点开始执行,次数为LENGTH(最后子结点)/ 2 - 1
update aa set number=25 where id=1303;
你究竟是求和还是并ID?求和是用SELECT SUM(NUMBER) FROM AA
如果是想要得到你括号你的效果的话,
那么的用"||"来
id number
13
1301 10
1302 15
1303
130301 15
130302 10.....如何用SQL语句把 13跟1303记录的number值为50,25
select * from aa
id number
13 50
1301 10
1302 15
1303 25
130301 15
130302 10
更新完成后我如何用select sum(number).....得到如下的值(1301+1302+130301+130102)即底层结点的值 number
50
是求和
update a set number =(select sum(b.number) from a b where length(b.id)=length(a.id)+2 ) ;
我不改变那两行的位置,我只是要求它的和
如
13 0
1301 80
1302 20
只能从子节点输入数据 根据子结点的数据相加成为父节点的值如何用SQL语句实现
注意子节点向下有民N层。也可能有兄弟节点。
id number parent_node_id
13 0
1301 10 13
130101 5 1301
130102 5 1301
1302 15 13
130201 5 1302
130202 5 1302
130203 5 1302
1303 13
130301 15 1303
130302 10 1303
或者如果你不想修改表,那么可能就要写过程来实现了。
select sum(number) from aa b where a.id = substr(b.id, 1, length(a.id))
where length(a.id) = X;
(若最后子结点为10,X = 8,为8,X = 6,.....)
只能从最后子结点开始执行,次数为LENGTH(最后子结点)/ 2 - 1