select itemtype,
       dateofoccor(日期)=dateofoccor,
       code(单据号)=code,
       ruku(入数量)=ruku,
       chuku (出数量)=chuku,
       结存数量 =(select sum(isnull(ruku,0))-sum(isnull(chuku,0)) from tb where id <=a.id) 
from tb a
where hpid = '001'
order by id