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.
SELECT AVG(Discount), SUM(Discount) FROM INVENTORY WHERE CarName = 'Baleno';
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
Step 1: Identify the table as INVENTORY which contains CarName and Discount columns
Step 2: Use WHERE clause to filter only Baleno cars: WHERE CarName = 'Baleno'
Step 3: Apply AVG() function to calculate average discount
Step 4: Apply SUM() function to calculate total discount
Step 5: Combine both aggregate functions in a single SELECT statement