日期:2014-05-18 浏览次数:20535 次
select code,code_sub,sum(imoney) imoney from table group by code,code_sub
WHTH CTE AS (select code,code_sub,sum(imoney) imoney from table group by code,code_sub ) SELECT *,(SELECT SUM(imoney) FROM CTE WHERE code = A.code) AS Gmoney FROM CTE A ORDER BY code,code_sub