EF Core
SELECT [e].[FirstName], [e].[LastName], [e].[EmployeeID]
FROM [Employees] AS [e]
@_outer_EmployeeID='1'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='1'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='2'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='2'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='3'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='3'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='4'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='4'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='5'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='5'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='6'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='6'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='7'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='7'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='8'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='8'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
@_outer_EmployeeID='9'
SELECT TOP(5) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = @_outer_EmployeeID
ORDER BY [o].[OrderDate] DESC
@_outer_EmployeeID2='9'
SELECT [o.Customer0].[CustomerID], [o.Customer0].[Address], [o.Customer0].[City], [o.Customer0].[CompanyName], [o.Customer0].[ContactName], [o.Customer0].[ContactTitle], [o.Customer0].[Country], [o.Customer0].[Fax], [o.Customer0].[Phone], [o.Customer0].[PostalCode], [o.Customer0].[Region], [o.OrderDetails0].[OrderID], [o.OrderDetails0].[ProductID], [o.OrderDetails0].[Discount], [o.OrderDetails0].[Quantity], [o.OrderDetails0].[UnitPrice]
FROM [Orders] AS [o1]
LEFT JOIN [Customers] AS [o.Customer0] ON [o1].[CustomerID] = [o.Customer0].[CustomerID]
INNER JOIN [Order Details] AS [o.OrderDetails0] ON [o1].[OrderID] = [o.OrderDetails0].[OrderID]
WHERE [o1].[EmployeeID] = @_outer_EmployeeID2
Impatient
SELECT [e].[FirstName] AS [FirstName], [e].[LastName] AS [LastName], (
SELECT TOP (5) [o].[OrderID] AS [OrderID], [o].[CustomerID] AS [CustomerID], [o].[EmployeeID] AS [EmployeeID], [o].[OrderDate] AS [OrderDate]
FROM [Orders] AS [o]
WHERE [o].[EmployeeID] = [e].[EmployeeID]
ORDER BY [o].[OrderDate] DESC
FOR JSON PATH
) AS [RecentOrders], (
SELECT TOP (5) [c].[ContactName] AS [ContactName], [c].[CompanyName] AS [CompanyName], SUM(([o_0].[UnitPrice] * CAST([o_0].[Quantity] AS decimal(18, 2))) * CAST(1 - [o_0].[Discount] AS decimal(18, 2))) AS [total]
FROM [Orders] AS [o_1]
INNER JOIN [Order Details] AS [o_0] ON [o_1].[OrderID] = [o_0].[OrderID]
LEFT JOIN (
SELECT [c_0].[CustomerID] AS [CustomerID], [c_0].[Address] AS [Address], [c_0].[City] AS [City], [c_0].[CompanyName] AS [CompanyName], [c_0].[ContactName] AS [ContactName], [c_0].[ContactTitle] AS [ContactTitle], [c_0].[Country] AS [Country], [c_0].[Fax] AS [Fax], [c_0].[Phone] AS [Phone], [c_0].[PostalCode] AS [PostalCode], [c_0].[Region] AS [Region]
FROM [Customers] AS [c_0]
) AS [c] ON [o_1].[CustomerID] = [c].[CustomerID]
WHERE [o_1].[EmployeeID] = [e].[EmployeeID]
GROUP BY [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
ORDER BY SUM(([o_0].[UnitPrice] * CAST([o_0].[Quantity] AS decimal(18, 2))) * CAST(1 - [o_0].[Discount] AS decimal(18, 2))) DESC
FOR JSON PATH
) AS [TopCustomers]
FROM [Employees] AS [e]