Find Order ID of Orders with Total Greater than Average in DB2



We can find all the ORDER_ID which are having ORDER_TOTAL greater than the average value of all the ORDER_TOTAL present in the ORDERS table using the sub-query.

For example, if we have below ORDERS table.

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


Below is the subquery to find out the desired data.

Example

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

The result of the above query will be as below.

ORDER_ID
ORDER_TOTAL
A22345
87960
A62998
80363
Updated on: 2020-11-30T09:32:42+05:30

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements