w3resource

SQL Exercises: Display the item name and price

SQL Basic Select Statement: Exercise-27 with Solution.

From the following table, write a SQL query to display the pro_name as 'Item Name' and pro_priceas 'Price in Rs.'

Sample table : item_mast

 PRO_ID PRO_NAME                       PRO_PRICE    PRO_COM
------- ------------------------- -------------- ----------
    101 Mother Board                    3200.00         15
    102 Key Board                        450.00         16
    103 ZIP drive                        250.00         14
    104 Speaker                          550.00         16
    105 Monitor                         5000.00         11
    106 DVD drive                        900.00         12
    107 CD drive                         800.00         12
    108 Printer                         2600.00         13
    109 Refill cartridge                 350.00         13
    110 Mouse                            250.00         12

 

Sample Solution :

-- This query selects specific columns and renames them for better readability.
-- It renames the 'pro_name' column to "Item Name" and the 'pro_price' column to "Price in Rs."
SELECT pro_name as "Item Name", pro_price AS "Price in Rs."
-- Specifies the table from which to retrieve the data (in this case, 'item_mast').
FROM item_mast;

Output of the Query:

Item Name	Price in Rs.
Mother Board	3200.00
Key Board	450.00
ZIP drive	250.00
Speaker	550.00
Monitor	5000.00
DVD drive	900.00
CD drive	800.00
Printer	2600.00
Refill cartridge	350.00
Mouse	250.00

Code Explanation:

The above SQL query selects the "pro_name" column and renames it as "Item Name", and the "pro_price" column and renames it as "Price in Rs." from the 'item_mast' table. The result will display two columns: "Item Name" and "Price in Rs."

Practice Online


Query Visualization:

Duration:

Query visualization of Find the item name and price in Rs. - Duration

Rows:

Query visualization of Find the item name and price in Rs. - Rows

Cost:

Query visualization of Find the item name and price in Rs. - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Average price of all products of the given manufacturer.
Next SQL Exercise: Items with a price over 250 in ASC order by price,name.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sql-exercises/sql-retrieve-exercise-27.php