[go: up one dir, main page]

0% found this document useful (0 votes)
29 views10 pages

HRCMEH56 - Aditya Bose - SQL Exercise - 2

The document contains the syntax and output for 10 SQL exercises involving queries on tables like Employees, Orders, Shippers, Products, OrderDetails, Customers. The exercises include queries to display employee details for a specific order, shipper name for an order, orders containing a specific product, orders from a city on a date, names of customers who ordered the most expensive product, category name of a product ordered in a specific quantity, product name with highest ordered quantity, customers who ordered after a date, customers who ordered less than a quantity, and total price of products in a specific order.

Uploaded by

ahdb
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)
29 views10 pages

HRCMEH56 - Aditya Bose - SQL Exercise - 2

The document contains the syntax and output for 10 SQL exercises involving queries on tables like Employees, Orders, Shippers, Products, OrderDetails, Customers. The exercises include queries to display employee details for a specific order, shipper name for an order, orders containing a specific product, orders from a city on a date, names of customers who ordered the most expensive product, category name of a product ordered in a specific quantity, product name with highest ordered quantity, customers who ordered after a date, customers who ordered less than a quantity, and total price of products in a specific order.

Uploaded by

ahdb
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/ 10

SQL Day 2 - Exercise 2

HRCMEH56 – Aditya Bose

1. Display the Employee details corresponding to


OrderID=10261.

Syntax

SELECT emp.EmployeeID, LastName, FirstName, BirthDate,


Photo, Notes
FROM Employees as emp INNER JOIN Orders as ord ON
emp.EmployeeID = ord.EmployeeID
WHERE OrderID LIKE '10261';

Screenshot

2. Display the ShipperName for OrderID=10318.

Syntax

SELECT ship.ShipperName
FROM Shippers as ship INNER JOIN Orders as ord ON

1
ship.ShipperID = ord.ShipperID
WHERE OrderID LIKE '10318';

Screenshot

3. Display the OrderIDs who ordered for an item which has 1


kg pkg. Unit.

Syntax

SELECT od.OrderID
FROM OrderDetails as od INNER JOIN Products as pd ON
od.ProductID = pd.ProductID
WHERE Unit LIKE '1 kg pkg.';

Screenshot

2
4. Display the Order date when the Customers from the
city, ‘Buenos Aires’ placed an order.

Syntax

SELECT ord.OrderDate
FROM Orders AS ord INNER JOIN Customers AS cus ON
ord.CustomerID = cus.CustomerID
WHERE City = 'Buenos Aires';

Screenshot

3
5. Display the Customer names who ordered the costliest
product.

Syntax

SELECT Cust.CustomerName
FROM Customers AS cust JOIN Orders AS ord ON
cust.CustomerID = ord.CustomerID
JOIN OrderDetails AS orddet ON ord.OrderID = orddet.OrderID
JOIN Products AS pro ON orddet.ProductID = pro.ProductID
WHERE pro.Price = (SELECT MAX(Price) FROM Products);

4
6. Display the Category name of the product which
was ordered in quantity=33.

Syntax

SELECT cat.CategoryName
FROM Categories AS cat JOIN Products AS pro ON
cat.CategoryID = pro.CategoryID
JOIN OrderDetails AS orddet ON pro.ProductID =
orddet.ProductID
WHERE orddet.Quantity LIKE '33';

Screenshot

5
7. Display the Product name which has the highest quantity of
order.

Syntax

SELECT pro.ProductName
FROM Products pro JOIN OrderDetails od ON pro.ProductID =
od.ProductID
WHERE od.Quantity = (SELECT MAX(Quantity) FROM
OrderDetails);

6
8. Display the Customer names who placed an order after
‘1997-02-07’.

Syntax

SELECT CustomerName
FROM Customers cus JOIN Orders ord ON cus.CustomerID =
ord.CustomerID
WHERE '1997-02-07' < ord.OrderDate;

Screenshot

7
9. Display the Customer names who ordered less than
quantity=2 in their orders.
Syntax

SELECT CustomerName
FROM Customers cus JOIN Orders ord ON
cus.CustomerID = ord.CustomerID
JOIN OrderDetails orddet ON ord.OrderID =
orddet.OrderID
WHERE orddet.Quantity < 2;

Screenshot

8
10. Display the sum of the price of products that was
ordered in the OrderID=10263.
Syntax

SELECT SUM(Price)
FROM Products pro JOIN OrderDetails ord ON
pro.ProductID = ord.ProductID
WHERE ord.OrderID = '10263';

Screenshot

9
10

You might also like