Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a SELECT statement that returns these column names and data from the Produ

ID: 667936 • Letter: W

Question

Write a SELECT statement that returns these column names and data from the Products table:
product_name The product_name column
list_price The list_price column
discount_percent                                                   The discount_percent column
discount_amount                                                    A column that’s calculated from the previous two columns
discount_price    A column that’s calculated from the previous three columns
Use the ROWNUM pseudo column so the result set contains only the first 5 rows.
Sort the result set by discount price in descending sequence.

Explanation / Answer

ANSWER:

There are two cases

1. If all the columns is already there in database with data then in that case query will be

In ORACLE

SELECT product_name , list_price,discount_percent,discount_amount,discount_price from PRODUCT ORDER BY discount_price DESC where ROWNUM < 6;

2. If only first 3 column is there in database and the next two columns needs to be calculated , in that case use the below query

In ORACLE

SELECT product_name , list_price , discount_percent , ((list_price*discount_percent)/100) AS discount_amount , (list_price - discount_amount) AS discont_price from PRODUCT ORDER BY discount_price DESC where ROWNUM < 6;

IN SQL SERVER

SELECT TOP(5) product_name , list_price , discount_percent , ((list_price*discount_percent)/100) AS discount_amount , (list_price - discount_amount) AS discont_price from PRODUCT ORDER BY discount_price DESC ;


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote