I want to take aggregate of NetQuatity
from table BillDetails
where this aggregated value should non-zero. I wrote a query as given below. But feels like it is not optimized. Is there anyone can refract this one. Any attempt will be appreciated.
SELECT * FROM
(
SELECT DISTINCT CustId, Name, SUM(NetQuantity) OVER(PARTITION BY CustId, Name) AS Quantity
FROM BillDetails
) T WHERE Quantity <> 0