SQL Exercises: Find the number of products over or equal to Rs 350
SQL Aggregate Functions: Exercise-22 with Solution
From the following table, write a SQL query to count the number of products whose price are higher than or equal to 350. Return number of products
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 counts the number of products in the 'item_mast' table where the 'pro_price' is greater than or equal to 350.
SELECT COUNT(*) AS "Number of Products"
-- 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' is greater than or equal to 350.
WHERE pro_price >= 350;
Output of the Query:
Number of Products 8
Code Explanation:
The said SQL query is counting the number of rows in the 'item_mast' table where the "pro_price" column is greater than or equal to 350. The result of the count will be stored in a column called "Number of Products".
Practice Online
Query Visualization:
Duration:
Rows:
Cost:
Practice Online
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Calculate the average price of all the products.
Next SQL Exercise: Compute the average price for unique companies.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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-aggregate-function-exercise-22.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics