Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a query to get the number of products that falls under each price bracket. Price bracket can be created using the following criteria. (

Write a query to get the number of products that falls under each price bracket.
Price bracket can be created using the following criteria.
(Hint: Price is higher than or equal to 10000 then TIER 1
Price between the 5500 and 10000 then TIER 2
Price less than or equal to 5500 then TIER 3)
Select only one option
SELECT
PRICE_BRACKET,
COUNT(PRICE_BRACKET) AS COUNT_OF_PRODUCTS
FROM PRODUCT
WHERE PRICE_BRACKET IN (
SELECT PRODUCT_ID,
PRODUCT_PRICE,
CASE
WHEN PRODUCT_PRICE >=10000 THEN 'TIER 1'
WHEN PRODUCT_PRICE BETWEEN 5500 AND 10000 THEN 'TIER 2'
WHEN PRODUCT_PRICE <=5500 THEN 'TIER 3'
ELSE PRODUCT_PRICE
END AS PRICE_BRACKET
FROM PRODUCT
) AS P
GROUP BY PRICE_BRACKET;
SELECT
PRICE_BRACKET,
COUNT(PRICE_BRACKET) AS COUNT_OF_PRODUCTS
FROM (
SELECT PRODUCT_ID,
PRODUCT_PRICE,
CASE
WHEN PRODUCT_PRICE >=10000 THEN 'TIER 1'
WHEN PRODUCT_PRICE BETWEEN 5500 AND 10000 THEN 'TIER 2'
WHEN PRODUCT_PRICE <=5500 THEN 'TIER 3'
ELSE PRODUCT_PRICE
END AS PRICE_BRACKET
FROM PRODUCT
) AS P
GROUP BY PRICE_BRACKET;
SELECT
PRICE_BRACKET,
PRICE_BRACKET
FROM (
SELECT PRODUCT_ID,
PRODUCT_PRICE,
CASE
WHEN PRODUCT_PRICE >=10000 THEN 'TIER 1'
WHEN PRODUCT_PRICE BETWEEN 5500 AND 10000 THEN 'TIER 2'
WHEN PRODUCT_PRICE <=5500 THEN 'TIER 3'
ELSE PRODUCT_PRICE
END AS PRICE_BRACKET
FROM PRODUCT
) AS P
GROUP BY PRICE_BRACKET;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions