Question 01 of 03

Complex Queries using Comparison, Range, and List Operators

Write SQL queries on tables Supplier, Part, and Supplies to: 1. Find pname, PID, and price of parts with price >= 200 and <= 600. 2. Find sname, SID, and branch of suppliers in 'local' branch or 'global' branch using IN / OR. 3. Find pname, PID, and price of parts where price is BETWEEN 200 and 600. 4. Find pname and color of parts having the word 'NET' anywhere in pname. 5. Find PID and pname of parts with pname either 'NUT' or 'BOLT'. 6. List suppliers who supplied parts on '2000-05-01', '2021-01-12', '2000-12-17', or '2021-01-10'. 7. Find all distinct costs of parts.

C++
-- 1. Parts with price >= 200 and <= 600 using comparison operators
SELECT PID, Pname, price 
FROM Part 
WHERE price >= 200 AND price <= 600;

-- 2. Suppliers in 'local' or 'global' branch using IN / OR
SELECT SID, Sname, branch 
FROM Supplier 
WHERE branch IN ('local', 'global');

-- 3. Parts with price BETWEEN 200 and 600
SELECT PID, Pname, price 
FROM Part 
WHERE price BETWEEN 200 AND 600;

-- 4. Parts having 'NET' anywhere in pname
SELECT Pname, color 
FROM Part 
WHERE Pname LIKE '%NET%';

-- 5. Parts with pname either 'NUT' or 'BOLT'
SELECT PID, Pname 
FROM Part 
WHERE Pname IN ('NUT', 'BOLT');

-- 6. Suppliers who supplied parts on specified dates
SELECT DISTINCT s.SID, s.Sname, sp.date_supplied
FROM Supplier s
JOIN Supplies sp ON s.SID = sp.SID
WHERE sp.date_supplied IN ('2000-05-01', '2021-01-12', '2000-12-17', '2021-01-10');

-- 7. All distinct costs of parts
SELECT DISTINCT price 
FROM Part 
ORDER BY price ASC;
Question 1 of 3