Nishtha Assignment
Nishtha Assignment
EXPLANATION 1:
This query retrieves information from the ORDERS and CUSTOMER tables, where
the customer numbers match, and it orders the results based on the customer
number in ascending order. Additionally, column aliases are used to rename
specific columns in the result set.
2. For each order placed on October 23, 2010, list the order number
along with the number and name of the customer that placed the order.
EXPLANATION 2:
This query retrieve information about orders placed on October 23, 2010 (O.ORDER_DATE
= '23-OCT-10'). It selects the order number, order date, customer number, and customer
name, and orders the result set based on the customer number
3. For each order, list the order number, order date, part number,
number of units ordered, and quoted price for each order line that
makes up the order.
THE CODE FOR FOLLOWING
SELECT O.ORDER_NUM AS ORDER_NUM_103,
O.ORDER_DATE, OL.PART_NUM, OL.NUM_ORDERED,
OL.QUOTED_PRICE
FROM ORDERS O, ORDER_LINE OL
WHERE O.ORDER_NUM=OL.ORDER_NUM;
EXPLANATION 3:
The query essentially retrieves information about order lines,
including the order number (renamed as ORDER_NUM_251),
order date, part number, number ordered, and quoted price.
The data is obtained by combining information from the
ORDERS and ORDER_LINE tables where the order numbers
match.
4. Use the IN operator to find the number and name of each customer
that placed an order on October 23, 2010
CODE FOR THE FOLLOWING
SELECT CUSTOMER_NUM, CUSTOMER_NAME FROM
CUSTOMER
WHERE CUSTOMER_NUM IN(SELECT CUSTOMER_NUM FROM
ORDERS
WHERE ORDER_DATE='23-OCT-10');
EXPLANATION 4 :
This query retrieve the customer numbers and names for customers who placed orders on
October 23, 2010. The IN clause is used to compare the CUSTOMER_NUM from the
CUSTOMER table with the result of the subquery, which returns customer numbers
associated with orders placed on the specified date.
5. Repeat Exercise 4, but this time use the EXISTS operator in your
answer
CODE FOR THE FOLLOWING
EXPLANATION 5:
This query retrieves the CUSTOMER_NUM and CUSTOMER_NAME from the CUSTOMER table for
customers who have placed an order on '23-OCT-10' (based on the existence of matching records in
the ORDERS table).
6. Find the number and name of each customer that did not place an
order on October 23, 2010.
CODE FOR FOLLOWING
EXPLANATION 6:
The main query selects customers (CUSTOMER_NUM and CUSTOMER_NAME) from the CUSTOMER
table, excluding those customers who have placed an order on the specified date ('23-OCT-10') based
on the subquery using NOT EXISTS.
7. For each order, list the order number, order date, part number, part
description, and item class for each part that makes up the order
CODE FOR FOLLOWING
EXPLANATION 7:
The provided SQL query retrieves information about each order, including the order number
(ORDER_NUM) and order date (ORDER_DATE). It also includes details about the items in each order,
such as the part number (PART_NUM), part description (DESCRIPTION), and item class (CLASS). The
information is obtained by combining data from the ORDERS, ORDER_LINE, and PART tables using
the WHERE clause to specify the relationships between these tables.
8. Repeat Exercise 7, but this time order the rows by item class and
then by order number.
CODE FOR FOLLOWING
EXPLANATION 8 :
The query retrieves specific columns from three tables
(ORDERS, ORDER_LINE, and PART) where certain
conditions are met. The result set is then ordered
based on the CLASS and ORDER_NUM columns
9. Use a subquery to find the rep number, last name, and first name of
each sales rep who represents at least one customer with a credit
limit of $10,000. List each sales rep only once in the results.
CODE FOR FOLLOWING
EXPLANATION 9 :
The given SQL query selects the representative number (REP_NUM), last name (LAST_NAME), and
first name (FIRST_NAME) from the REP table for representatives whose REP_NUM is present in the
result of a subquery. The subquery itself selects REP_NUM from the CUSTOMER table for customers
with a CREDIT_LIMIT greater than or equal to 10000
10. Repeat Exercise 9, but this time do not use a subquery
EXPLANTION 10 :
The query retrieves distinct combinations of representative
number, last name, and first name from the REP table, along
with the representative number from the CUSTOMER table,
where the credit limit of the customer is greater than or equal
to 10000.