Query from the result of another query .
- basic table
select * from Customers;
select * from [Order Details];
select * from Orders;
- first query
select o.CustomerID,sum(od.UnitPrice*od.Quality) as Amount
from Orders o, [Order Details] od
where o.OrderID = od.OrderID
group by o.CustomerID ;
- secong query based on first query
select Avg(temp.Amount) as average from (
select sum(od.UnitPrice*od.Quality) as Amount
from Orders o, [Order Details] od
where o.OrderID = od.OrderID
group by o.CustomerID
) as temp;