【SQL0001】Query from the result of another query

来源:互联网 发布:网吧吃鸡优化 编辑:程序博客网 时间:2024/06/05 09:42

Query from the result of another query .

  • basic table
select * from Customers;select * from [Order Details];select * from Orders;

three tables

  • first query
select o.CustomerID,sum(od.UnitPrice*od.Quality) as Amountfrom Orders o, [Order Details] odwhere o.OrderID = od.OrderID group by o.CustomerID ;

the result of CustomerID and Amount

  • secong query based on first query
select Avg(temp.Amount) as average from (select sum(od.UnitPrice*od.Quality) as Amountfrom Orders o, [Order Details] odwhere o.OrderID = od.OrderID group by o.CustomerID ) as temp;

the average of all  Amount

0 0
原创粉丝点击