w3resource

SQL Exercises: Display the average price of each company's products, along with their code

SQL Aggregate Functions: Exercise-23 with Solution

Write a SQL query to display the average price of each company's products, along with their code.

Sample table: item_mast


Sample Solution:

SELECT AVG(pro_price) AS "Average Price", 
       pro_com AS "Company ID"
    FROM item_mast
GROUP BY pro_com;

Output of the Query:

Average Price			Company ID
250.0000000000000000		14
650.0000000000000000		12
3200.0000000000000000		15
5000.0000000000000000		11
1475.0000000000000000		13
500.0000000000000000		16

Practice Online


Query Visualization:

Duration:

Query visualization of Display the average price of each company's products, along with their code - Duration

Rows:

Query visualization of Display the average price of each company's products, along with their code - Rows

Cost:

Query visualization of Display the average price of each company's products, along with their code - Cost

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

Previous: Write a SQL query to find the number of products with a price more than or equal to Rs.350.
Next: Write a query in SQL to find the sum of the allotment amount of all departments.

What is the difficulty level of this exercise?