w3resource

SQL Exercises: Find all products between Rs.200 and Rs.600

SQL Basic Select Statement: Exercise-25 with Solution.

From the following table, write a SQL query to select a range of products whose price is in the range Rs.200 to Rs.600. Begin and end values are included. Return pro_id, pro_name, pro_price, and pro_com.

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 all columns from the 'item_mast' table.
SELECT *
-- Specifies the table from which to retrieve the data (in this case, 'item_mast').
FROM item_mast
-- Filters the rows to only include those where the 'pro_price' column is between 200 and 600 (inclusive).
WHERE pro_price BETWEEN 200 AND 600;

Output of the Query:

pro_id		pro_name	pro_price	pro_com
102		Key Board	450.00		16
103		ZIP drive	250.00		14
104		Speaker		550.00		16
109		Refill cartridge 350.00		13
110		Mouse		250.00		12

Code Explanation:

The said SQL query that retrieves all columns from the table 'item_mast' where the column "pro_price" has a value between 200 and 600. The "SELECT *" statement returns all columns, and the "WHERE pro_price BETWEEN 200 AND 600" filters the results to only show rows where the value of the "pro_price" column falls within that range.

Relational Algebra Expression:

Relational Algebra Expression: Find all the products with a price between Rs.200 and Rs.600.

Relational Algebra Tree:

Relational Algebra Tree: Find all the products with a price between Rs.200 and Rs.600.

Practice Online


Query Visualization:

Duration:

Query visualization of Find all the products with a price between Rs.200 and Rs.600 - Duration

Rows:

Query visualization of Find all the products with a price between Rs.200 and Rs.600 - Rows

Cost:

Query visualization of Find all the products with a price between Rs.200 and Rs.600 - Cost

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

Previous Python Exercise: Economics, Chemistry listed at end of 1970 as winners.
Next Python Exercise: Average price of all products of the given manufacturer.

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://w3resource.com/sql-exercises/sql-retrieve-exercise-25.php