- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How will you find the ORDER_ID of all the orders having ORDER_TOTAL greater than the average of ORDER_TOTAL in ORDER's DB2 table
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 |
- Related Articles
- Write the DB2 SQL query to find the third highest ORDER_TOTAL in a ORDERS DB2 table
- How will you create a new TRIGGER on the ORDERS DB2 table? Give the syntax of TRIGGER
- Write a DB2 query to find out all the duplicate INVOICE_ID in ORDERS DB2 table?
- How will you find out all the indexes which are built in a particular DB2 table?
- How can you revert all the DB2 table changes done in a COBOL-DB2 program?
- How to find all the foreign keys of a DB2 table TAB1?
- Write the syntax to declare a scrollable cursor on the ORDERS DB2 table.
- Write a SQL query to count the number of duplicate TRANSACTION_ID in an ORDERS DB2 table
- How to get the list of all COBOL-DB2 programs using a DB2 table TAB1?
- What's the meaning of the phrase 'what you seek is seeking you'?
- Python – Average of digit greater than K
- How to find out all the indexes for a DB2 table TAB1?
- How will you detect the condition of the end of cursor rows in a COBOL-DB2 program?
- How to find the primary key of a DB2 table TAB1?
- Count the number of words having sum of ASCII values less than and greater than k in C++

Advertisements