如何查詢ORDERS資料庫表中ORDER_TOTAL大於ORDER_TOTAL平均值的所有訂單的ORDER_ID?


我們可以使用子查詢查詢ORDERS表中ORDER_TOTAL大於所有ORDER_TOTAL平均值的所有ORDER_ID。

例如,如果我們有以下ORDERS表。

ORDER_ID
ORDER_TOTAL
A22345
1867
A62998
5634
A56902
7615
A56911
87960
A56915
132
A56918
80363


以下是查詢所需資料的子查詢。

示例

SELECT ORDER_ID, ORDER_TOTAL FROM ORDERS
   WHERE ORDER_TOTAL > (SELECT AVG(ORDER_TOTAL) FROM ORDERS)

上述查詢的結果如下所示。

ORDER_ID
ORDER_TOTAL
A22345
87960
A62998
80363

更新於:2020年11月30日

瀏覽量:158

啟動您的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.