[go: up one dir, main page]

0% found this document useful (0 votes)
9 views1 page

Lec 32 SQL Practice

The document contains SQL queries for selecting products from a database. It includes examples of adding a column to categorize products by price and sorting products based on category priority. The queries demonstrate how to use conditional statements to manipulate and organize data effectively.

Uploaded by

koulibalyhamam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Lec 32 SQL Practice

The document contains SQL queries for selecting products from a database. It includes examples of adding a column to categorize products by price and sorting products based on category priority. The queries demonstrate how to use conditional statements to manipulate and organize data effectively.

Uploaded by

koulibalyhamam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

select * from Products

--Example1 : Add a column to categorize each product into categories high, medium &
low
select
*,
case
when Price > 500 then 'High'
when Price<=500 and Price>=200 then 'Medium'
else 'Low'
end as [High/Medium/Low]
from products
-----------------------------------------------Test
select
*,
case
when Price > 500 then 'High'
when Price<=500 and Price>=200 then 'Medium'
end as [High/Medium/Low]
from products

--Example2 : Provide priority to each category & sort the data according to that
priority
select * from Products
order by
case
when Category in ('Electronics') then 1
when Category in ('Furniture') then 2
else 3
end

-----------------------test

select * from Products


order by
case
when Category in ('Electronics') then 1
when Category in ('Furniture') then 2
when Category = 'Accessories' then 3
end

You might also like