w3resource

SQL Exercises: Calculate the average price of all the products


From the following table, write a SQL query to calculate the average product price. Return average product price.

Sample table: item_mast

 PRO_ID PRO_NAME                       PRO_PRICE    PRO_COM
------- ------------------------- -------------- ----------
    101 Mother Board                    3200.00         15
    102 Key Board                        450.00         16
    103 ZIP drive                        250.00         14
    104 Speaker                          550.00         16
    105 Monitor                         5000.00         11
    106 DVD drive                        900.00         12
    107 CD drive                         800.00         12
    108 Printer                         2600.00         13
    109 Refill cartridge                 350.00         13
    110 Mouse                            250.00         12

Sample Solution:

-- This query calculates the average 'pro_price' from the 'item_mast' table and assigns it the alias "Average Price".
SELECT AVG(pro_price) AS "Average Price"
-- Specifies the table from which to retrieve the data (in this case, 'item_mast').
FROM item_mast;

Output of the Query:

Average Price
1435.0000000000000000

Code Explanation:

The said SQL query calculates the average price of all items in the 'item_mast' table. The "AVG(pro_price)" function calculates the average value of the "pro_price" column, and the "AS 'Average Price'" clause gives the result column a label of "Average Price".


Practice Online



For more Practice: Solve these Related Problems:

  • Write a SQL query to calculate the average product price for products with a price greater than 500.
  • Write a SQL query to calculate the average product price for products with a price less than 1000.
  • Write a SQL query to calculate the average product price for products with a price between 200 and 800.
  • Write a SQL query to calculate the average product price for products with a price greater than 1000 and less than 3000.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Count how many salesmen each day register orders.
Next SQL Exercise: Find the number of products over or equal to Rs 350.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.