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

Oracle Assignment2

Uploaded by

yaasiryare2001
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)
6 views2 pages

Oracle Assignment2

Uploaded by

yaasiryare2001
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

Oracle Assignment

1) Using Orders Table, write a query that tells the highest QTY that is
ordered.
 SELECT MAX(Qty) AS HighestQty FROM Orders;
2) Using Drugs Table, write a query that displays the lowest Price.
 SELECT MIN(Price) AS LowestPrice FROM Drugs;
3) Using Drugs and Orders, write a query that creates an INNER JOIN of
these two tables.
 SELECT o.Orderid, o.PatientId, d.DrugName, o.Qty, o.Orderdate FROM
Orders o
INNER JOIN Drugs d ON o.DrugId = d.DrugId;
4) Using Patients and Orders, write a query that creates an INNER JOIN of
these two Table.
 SELECT o.Orderid, p.PatientName, o.DrugId, o.Qty, o.Orderdate
FROM Orders o
INNER JOIN Patients p ON o.PatientId = p.PatientId;
5) Using Orders, write a query that COUNTS the number of Orders that is
made at (2023-12-14)
 SELECT COUNT(o.OrderId) AS NumberOfOrders
FROM Orders o
WHERE o.OrderDate = TO_DATE('23-Dec-14', 'DD-Mon-YY');
6) Using Orders, write a query that displays Orderdate and the SUM of the
Total Qty that is Made but use group by OrderDate
 SELECT Orderdate, SUM(Qty) AS TotalQty
FROM Orders
GROUP BY Orderdate;
7) Using Drugs Table, write a query that displays DrugType and the SUM of
the Total Quantity but use group by DrugType
 SELECT DrugType, SUM(Quantity) AS TotalQuantity
FROM Drugs
GROUP BY DrugType;
8) Using Patients,Drugs and Orders, write a query that joins triple tables and
the output is like this:
 SELECT o.Orderid, o.PatientId, p.PatientName, o.DrugId, d.DrugName,
o.Qty, d.Price,
(o.Qty * d.Price) AS Total, o.Orderdate
FROM Orders o
INNER JOIN Patients p ON o.PatientId = p.PatientId
INNER JOIN Drugs d ON o.DrugId = d.DrugId;
9) Write a query that subtracts the ordered drug quantity and drug store
quantity to display the remaining drug quantity in the store.
 SELECT d.DrugId, d.DrugName, d.Quantity AS InitialQuantity,
(d.Quantity - COALESCE(SUM(o.Qty), 0)) AS RemainingQuantity
FROM Drugs d
LEFT JOIN Orders o ON d.DrugId = o.DrugId
GROUP BY d.DrugId, d.DrugName, d.Quantity;

You might also like