(ii) Display Name and Final Price (product of Price and (1-Discount)) of all products whose discount is known. The column heading ‘Final Price’ should also be displayed.

Answer:

Answer by student

The SQL statement is:

SELECT Name, Price * (1 - Discount) AS ‘Final Price’ FROM Product WHERE Discount IS NOT NULL;

Detailed answer by teachoo

-lock-

  • To display the name and final price of products whose discount is known, we need to use the SELECT statement with the column names and an expression.
  • The expression is Price * (1 - Discount), which calculates the final price after applying the discount.
  • We can also use the AS keyword   to give an alias or a new name to the expression column. In this case, we want to name it as ‘Final Price’.
  • We also need to use the WHERE clause to filter the rows that match the condition. The condition is that the discount column should not be NULL , which means it has a known value.

The SQL query for this is:

SELECT Name, Price * (1 - Discount) AS 'Final Price' FROM Product WHERE Discount IS NOT NULL;

This query will display the name and final price columns from the table Product for the rows where discount is not NULL.

The output will look like this:

Name

Final Price

Pen

9

Shirt

400

Watch

850

-endlock-

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.