如何查找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 |
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP