with tablename as ( 你的select ) select 你要的列, sum(totalprice) from tablename group by你要的列 [解决办法]
SQL code
WITH tb AS(select ...,(b.quantity-isnull(sum(c.quantity),0))*b.unit_price as totalprice from table b left join table2 c on ... where ... group by ...)SELECT SUM(totalprice )FROM tb [解决办法]