This website is for reference purposes only. Users are responsible for any misuse. The owner is not liable for any consequences.
Back to Database Management Systems (Laboratory)
4.1.1EasyCODE

SQL Basic Operations

Question

Solution

SQL

-- -- Q1
SELECT *
FROM orders
WHERE customer_id = 1;


-- -- Q2
SELECT DISTINCT product_name
FROM orders;


-- -- Q3
SELECT product_name, SUM(quantity) AS total_sold
FROM orders
WHERE supplier_id = 1
GROUP BY product_name
ORDER BY total_sold DESC
LIMIT 1;


-- -- Q4
SELECT product_category, STRING_AGG(product_name, ', ') AS products
FROM orders
GROUP by product_category;


-- -- Q5
SELECT product_name, unit_price
FROM orders
WHERE unit_price > (SELECT AVG(unit_price) FROM orders);


-- -- -- Q6
SELECT *
FROM orders;


-- -- -- Q7 
SELECT DISTINCT product_name
FROM orders
WHERE (extract(year FROM order_date)) = 1997;


-- -- -- Q8 
SELECT *
FROM orders
WHERE order_id = 1; 

8/8 test cases passed

No hidden test cases