1.
select the name, customer ID of customers,order
value and discounted price of the items he/she ordered
receiving a discount of 10% as an offer when his/her
order value is more than 300$.
SELECT
c.first_name || ' ' || c.last_name AS name,
c.customer_id,
o.amount AS order_value,
o.amount * 0.9 AS discounted_price
FROM
Customers c
JOIN
Orders o ON c.customer_id = o.customer_id
WHERE
o.amount > 300;
2.Generate a report of the customers whose shipping_IDs
are 2,4 and 5 . This report will contain (1) First Name
, (2) last name,(3) item ordered, (4) amount (5)
shipping status.
SELECT
c.first_name,
c.last_name,
o.item,
o.amount,
s.status AS shipping_status
FROM
Customers c
JOIN
Orders o ON c.customer_id = o.customer_id
JOIN
Shippings s ON c.customer_id = s.customer
WHERE
s.shipping_id IN (2, 4, 5);
3.Add two columns in Orders Table. (1) Order date as
ODT, (2) shop no as Sh_no.
Append the date column by current date and shop no by 0.
chang the shop no to 200 if order amount lies between
300 and 5000 (both inclusive) and item is either a mouse
or a monitor.
-- 1. Add columns to Orders table
ALTER TABLE Orders
ADD COLUMN ODT DATE,
ADD COLUMN Sh_no INTEGER;
-- 2. Update the new columns with current date and 0 for
shop no
UPDATE Orders
SET ODT = CURRENT_DATE,
Sh_no = 0;
-- 3. Update Sh_no to 200 conditionally
UPDATE Orders
SET Sh_no = 200
WHERE Amount BETWEEN 300 AND 5000
AND Item IN ('Mouse', 'Monitor');