4,707 questions
Check the query for the third problem:
select *,
sum(Price) over (partition by Category, Unit order by SerialNo) as RunningTotal,
case when lead(SerialNo) over (partition by Category, Unit order by SerialNo) is null
then cast(sum(Price) over (partition by Category, Unit) as varchar(max)) else '' end as TotalValue
from MyTable
order by Category, Unit, SerialNo