0% found this document useful (0 votes)
51 views1 page

FINAL

The document is a practice test containing 8 multiple choice and query questions about SQL subqueries. Some key points covered include: 1. Writing queries using subqueries to display customer information including purchases, payments, cancellations and debt amounts. 2. A query to find products that need to be returned to stock based on canceled orders. 3. Questions test knowledge of valid statements about subqueries, including that the outer and inner queries can access different tables and inner queries can use GROUP BY. 4. Additional queries demonstrate using subqueries to find high-risk customers, create a new table, and retrieve inventory values.
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)
51 views1 page

FINAL

The document is a practice test containing 8 multiple choice and query questions about SQL subqueries. Some key points covered include: 1. Writing queries using subqueries to display customer information including purchases, payments, cancellations and debt amounts. 2. A query to find products that need to be returned to stock based on canceled orders. 3. Questions test knowledge of valid statements about subqueries, including that the outer and inner queries can access different tables and inner queries can use GROUP BY. 4. Additional queries demonstrate using subqueries to find high-risk customers, create a new table, and retrieve inventory values.
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/ 1

Nguyễn Văn Hưng 20021370 

Courses Các khoá học của tôi Vietnamese (‎ vi)‎ Tìm k

Nhà của tôi  Các khoá học của tôi  2122I_INT2211_22  6 December - 12 December  FINAL PRACTICE TEST!

Bắt đầu vào lúc Sunday, 12 December 2021, 8:32 PM


Trạng thái Đã xong  Bảng câu hỏi
Kết thúc lúc Sunday, 12 December 2021, 9:32 PM
1 2 3 4 5 6 7 8
Thời gian thực hiện 1 giờ
Điểm Chưa được chấm điểm
Hiển thị từng trang một

Câu Hỏi 1 Hoàn thành Đặt cờ Hoàn thành việc xem lại

Because some orders were canceled but the system still charged customers.
Write 01 query to display customerName, purchasedMoney, paidMoney, canceledMoney, debt. If the canceledMoney = debt, add the value "Mistake" to the Note column.

SELECT c.customerName AS customerName,

(SELECT SUM(od.priceEach * od.quantityOrdered)

FROM orderdetails od JOIN orders o ON od.orderNumber = o.orderNumber

WHERE o.customerNumber = c.customerNumber

GROUP BY customerNumber) AS purchasedMoney,

(SELECT SUM(amount) from payments p

WHERE p.customerNumber = c.customerNumber

GROUP BY customerNumber) AS paidMoney,

(SELECT SUM(od.priceEach * od.quantityOrdered)

FROM orderdetails od JOIN orders o ON od.orderNumber = o.orderNumber

WHERE o.customerNumber = c.customerNumber AND o.status = "Cancelled"

GROUP BY customerNumber) AS canceledMoney,

(SELECT purchasedMoney - paidMoney) AS debt,

(SELECT IF(debt = canceledMoney , "Mistake", "")) AS note

FROM customers c

ORDER BY debt DESC;

Câu Hỏi 2 Hoàn thành Đặt cờ

Write 01 query to display codes of products that need to be sent back to stock and the corresponding quantity to send back to stock (hint: get information from canceled orders (status is
'canceled')).

Using subquery and sort ascending by the product code.

SELECT od.productCode, SUM(od.quantityOrdered) AS totalSendBack, o.status

FROM orders o

INNER JOIN orderdetails od ON od.orderNumber = o.orderNumber

WHERE o.status = "Cancelled"

GROUP BY od.productCode

ORDER BY od.productCode ASC;

Câu Hỏi 3 Đúng Đặt cờ

Choose the correct clauses!

A. Subqueries can be nested in the UPDATE , DELETE , INSERT , ORDER BY and SELECT data manipulation (DML) statements.

B. A subquery can itself include one or more subqueries

C. A subquery is also called an inner query or inner select, while the statement containing a subquery is also called an outer query or outer select.

D. Subqueries with the keyword NOT IN also return a list of zero or more values.

Câu trả lời của bạn đúng

The correct answers are:


A subquery can itself include one or more subqueries,

Subqueries with the keyword NOT IN also return a list of zero or more values.,

A subquery is also called an inner query or inner select, while the statement containing a subquery is also called an outer query or outer select.

Câu Hỏi 4 Hoàn thành Đặt cờ

Write 01 query to display full information about customers with the largest and smallest DEBT amounts greater than 0 in the same data table. Note, it doesn't matter whether the order status is
cancelled or not.

Hint: Using UNION

(SELECT customers.customerName AS customerName, customers.customerNumber,

(SELECT SUM(orderdetails.quantityOrdered * orderdetails.priceEach)

FROM orders

INNER JOIN orderdetails ON orders.orderNumber = orderdetails.orderNumber

WHERE orders.customerNumber = customers.customerNumber

GROUP BY orders.customerNumber) AS purchasedMoney,

(SELECT SUM(payments.amount) FROM payments

WHERE payments.customerNumber = customers.customerNumber

GROUP BY payments.customerNumber) AS paidMoney,

(SELECT purchasedMoney - paidMoney) AS DEBT

FROM customers

ORDER BY DEBT DESC LIMIT 1)

UNION

(SELECT customers.customerName AS customerName, customers.customerNumber,

(SELECT SUM(orderdetails.quantityOrdered * orderdetails.priceEach)

FROM orders

INNER JOIN orderdetails ON orders.orderNumber = orderdetails.orderNumber

WHERE orders.customerNumber = customers.customerNumber

GROUP BY orders.customerNumber) AS purchasedMoney,

(SELECT SUM(payments.amount) FROM payments

WHERE payments.customerNumber = customers.customerNumber

GROUP BY payments.customerNumber) AS paidMoney,

(SELECT purchasedMoney - paidMoney) AS DEBT

FROM customers

HAVING DEBT > 0

ORDER BY DEBT ASC LIMIT 1);

Câu Hỏi 5 Đúng Đặt cờ

Which of the following statement(s) is TRUE regarding subqueries?

A. There is no limit on the number of subquery levels in the WHERE clause of a SELECT statement

B. Outer query and inner query must get data from the same table

C. Outer query and inner query can get data from different tables

D. Inner queries in WHERE clause can contain ORDER BY

E.
Inner query can contain GROUP BY clause

Câu trả lời của bạn đúng

The correct answers are:


Outer query and inner query can get data from different tables,

Inner query can contain GROUP BY clause

Câu Hỏi 6 Hoàn thành Đặt cờ

Write 01 query to display names of customers who are at risk of having non-performing debt (whose debt/purchase percentage is greater than 8%.). Show percentages to 2 decimal places.

SELECT c.customerName,

(SELECT SUM(od.priceEach * od.quantityOrdered)

FROM orderdetails od JOIN orders o ON od.orderNumber = o.orderNumber

WHERE o.customerNumber = c.customerNumber

GROUP BY customerNumber) AS totalBuy,

(SELECT SUM(amount)

FROM payments p

WHERE p.customerNumber = c.customerNumber

GROUP BY p.customerNumber) AS totalPay,

(SELECT totalBuy - totalPay) AS totalDebt,

(SELECT ROUND(totalDebt / totalBuy * 100, 2)) AS percentage

FROM customers c

HAVING percentage > 8;

Câu Hỏi 7 Hoàn thành Đặt cờ

Create a new table based on the definition of table products, including any column attributes and indexes defined in the table products, name it new_products (Hint: use LIKE).

Insert into table new_products all entries of table products that have productLine is ‘Planes’.

CREATE TABLE new_products LIKE products;

INSERT INTO new_products

SELECT * FROM products

WHERE products.productLine = "Planes";

Câu Hỏi 8 Hoàn thành Đặt cờ

Write 01 query to display information of productlines and their corresponding inventory money

(Hint: Inventory money could be calculated using buy price).

SELECT p.productLine, (p.quantityInStock * p.buyPrice) AS "inventory money"

FROM products p

GROUP BY p.productLine;

Hoàn thành việc xem lại

Link for submitting the presentation about project


◄ Normalization - Ex 2 Chuyển tới...
applications (video) ►

Trường Đại học Công nghệ, Đại học Quốc Gia Hà Nội

You might also like