如果用一条sql语句,把一个表内,具有相同父类编号的子类别号的数量累加到父类编号上
表名叫 bs_rep_day_lh ,
现在的数据是这样的:
-----------------------------
c_ptid F_STOCKSYS
----------------------------
001 null
001001 10
001002 20
处理后是这样的
-----------------------------
c_ptid F_STOCKSYS
----------------------------
001 30 --这里变为30
001001 10
001002 20
我的sql是这样写的:但是报子查询返回的结果是对于一条记录的,我不知道那里错了,谢谢帮助
select a.c_ptid,
(
select sum(isnull(a.F_STOCKSYS,0))
from bs_rep_day_lh b
where b.D_date = '2004-8-1' and left(a.c_ptid,len(b.c_ptid)) = b.c_ptid
) as depots
from bs_rep_day_lh a ,bs_rep_day_lh b
where a.d_date = '2004-8-1' and a.d_date = b.d_date
and left(a.c_ptid,len(b.c_ptid)) = b.c_ptid
group by a.c_ptid
order by a.c_ptid