(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-