
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 |
Advertisements