괄호에 있는 select가 우선으로 실행
총 주문금액 상위 10%로인 사람들의 주문내역 표시
/* 총 주문금액 상위 10%로인 사람들의 주문내역 표시*/
SELECT SalesOrderID, CustomerID
FROM SalesOrder
WHERE CustomerID IN (
SELECT TOP 10 PERCENT so.CustomerID
FROM SalesOrder so
INNER JOIN SalesOrderDetail sod
ON (so.SalesOrderID = sod.SalesOrderID)
GROUP BY so.CustomerID
ORDER BY SUM(sod.SubTotal) DESC
);
SELECT *
FROM
(SELECT CustomerID, FirstName
FROM Customer
)
tmp_table;
SELECT AVG(Order_Total)
FROM(
SELECT
SalesOrderID,
SUM(SubTotal) AS Order_Total
FROM SalesOrderDetail
GROUP BY SalesOrderID
) tbl_order_total;
SELECT * FROM SalesOrder
WHERE
DATEDIFF(day, OrderDate, ShipDate) <= (
SELECT AVG(DATEDIFF(day, OrderDate, ShipDate))
FROM SalesOrder
);