Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views2 pages

Code

Uploaded by

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

Code

Uploaded by

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

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');

You might also like