想通了:
select TS.Order_no, part_no, cost_per_line,
case when Order_no = (select top 1 Order_no from #tempsales
where cust_po = TS.cust_po
order by Order_no asc)
then (select sum(cost_per_line)
from #tempsales
where Order_no <= TS.Order_no
and cust_po = TS.cust_po)
else '0' end as 'Sub Total',
case when Order_no = (select top 1 Order_no from #tempsales
where cust_po = TS.cust_po
order by Order_no asc)
then (select CAST(ROUND(SUM(cost_per_line), 2, 1) AS DECIMAL(18, 2))
from #tempsales)
else '0' end as 'Grand Total'
from #tempsales TS
SQL Server 2000是***远远超出死*** - 它的干尸。现在是时候从这个**升级到现在的一个loooooooong时间了! –
是的,没有开玩笑...............不幸的是,我的公司正在从SQL 2000到2016年进行大规模升级,直到12月份,我基本上坚持了它,所以真的有一些帮助,而不是忽略问题很棒。 – tfenwick11