Logic for correlated subquery
hi i want to know the logic of this query..i mean how data flows.....
i want to know what do the
where subtotal <=
please help me to understand this with the help of dfd if necessary
USE AdventureWorks
SELECT TerritoryID, SubTotal, SalesPersonID, SalesOrderID
FROM Sales.SalesOrderHeader AS SO1
WHERE SubTotal <= (SELECT MAX(SO2.SUBTOTAL) FROM Sales.SalesOrderHeader AS SO2
WHERE SO1.TerritoryID = SO2.TerritoryID
AND SO1.SubTotal < = SO2.SubTotal
HAVING COUNT(SubTotal) <= 5)
ORDER BY TerritoryID,SubTotal DESC;
|