Question 31 of 32intermediate🔧 ApplyShort Answer1 mark

Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following: Calculate the average discount and total discount available on Baleno cars.

Correct Answer

SELECT AVG(Discount), SUM(Discount) FROM INVENTORY WHERE CarName = 'Baleno';

Exercise: EXERCISE | Q: 8(d) | (Page 50)
For More Understanding

Explanation

This query uses aggregate functions AVG() and SUM() on the Discount column of the INVENTORY table. The WHERE clause filters records to only include cars named 'Baleno'. The AVG() function calculates the average discount value, while SUM() calculates the total discount. Both calculations are done in a single query as requested.

Solution Steps

  1. Step 1: Identify the table as INVENTORY which contains CarName and Discount columns

  2. Step 2: Use WHERE clause to filter only Baleno cars: WHERE CarName = 'Baleno'

  3. Step 3: Apply AVG() function to calculate average discount

  4. Step 4: Apply SUM() function to calculate total discount

  5. Step 5: Combine both aggregate functions in a single SELECT statement