Professional Documents
Culture Documents
Response: The above query extracts all those Customer Name who have ordered the product Coffee
Table.
Q2. Compose a relational algebra expression that would find every order that requested (included) both
of these two products: End Table and Coffee Table. The output of this relational algebra expression
should show Order_ID and Order_Date. Hint: use a division operator concept.
Response:
RESULT_ORDERS<-ORDER_ALL PRODUCT_ALL
Q3. Compose a SQL statement that is equivalent to Question 1 above. Note, you might want to try and
execute this SQL statement against the PVF database in SQL Server 2014 to see if it works as intended.
Response:
SELECT CUSTOMER_NAME FROM (SELECT CUSTOMER_ID FROM
(SELECT DISTINCT ORDER_ID FROM ORDER_LINE_T A JOIN
(SELECT * FROM PRODUCT_T WHERE PRODUCT_NAME='COFFEE TABLE')B ON
A.PRODUCT_ID=B.PRODUCT_ID) CUST
JOIN ORDER_T ORD ON CUST.ORDER_ID=ORD.ORDER_ID)CUST_NAME JOIN CUSTOMER_T NAME
ON CUST_NAME.CUSTOMER_ID=NAME.CUSTOMER_ID
Q4. Compose an SQL statement that is equivalent to Question 2 above. Note, you might want to try and
execute this SQL statement against the PVF database in SQL Server 2014 to see if it works as intended.
Response:
Response:
SELECT A.CUSTOMER_ID,B.CUSTOMER_NAME FROM (SELECT CUSTOMER_ID,COUNT(ORDER_ID) AS
TOT_ORD FROM ORDER_T
WHERE YEAR(ORDER_DATE)=2011 GROUP BY CUSTOMER_ID
HAVING COUNT(ORDER_ID)>=2) A INNER JOIN CUSTOMER_T B ON A.CUSTOMER_ID=B.CUSTOMER_ID
Q6. For each customer who submitted at least one order, show Order_ID, Customer_ID, and Order_Date
of the recent two orders. Note: if a customer submitted only one order, that customer order should also
be in the result (output) table. Hint: use a correlated nested query to answer this top N (where N>1) per
group question.
Response: