Вы находитесь на странице: 1из 11

DWI PUTRI ERLINDA SARASWATI

PRA-S2 MMI
ILMU KOMPUTER UGM

Single entity
1. Prepare a list of offices sorted by country, state, city.

SELECT * FROM `offices` ORDER BY country

SELECT * FROM `offices` ORDER BY state DESC

SELECT * FROM `offices` ORDER BY city


DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

2. How many employees are there in the company?

SELECT COUNT(1) FROM `employees`

3. What is the total of payments received?

SELECT SUM(amount) FROM `payments`

4. List the product lines that contain 'Cars'.

SELECT DISTINCT productLine FROM `products` WHERE productLine LIKE


'%Cars%'

5. Report total payments for October 28, 2004.

SELECT SUM(amount) as total_pembayaran FROM `payments`


WHERE paymentDate='2004-10-28'

6. Report those payments greater than $100,000.

SELECT amount FROM `payments` WHERE amount > 100000


DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

7. List the products in each product line.

SELECT productName FROM `products` ORDER by productline

8. How many products in each product line?

SELECT productLine, COUNT(1) as banyak FROM `products`


GROUP BY productLine
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

9. What is the minimum payment received?

SELECT MIN(amount) FROM `payments`

10. List all payments greater than twice the average payment.

SELECT paymentDate, amount FROM `payments` WHERE amount >


(SELECT AVG(amount)*2 FROM payments)

11. What is the average percentage markup of the MSRP on buyPrice?

SELECT AVG(((MSRP-buyPrice)DIV buyPrice)*100) as kenaikan


FROM `products`
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

12. How many distinct products does ClassicModels sell?

SELECT DISTINCT COUNT(1) as banyak FROM `products`

13. Report the name and city of customers who don't have sales representatives?

SELECT customerName, city, salesRepEmployeeNumber FROM


`customers` WHERE salesRepEmployeeNumber IS NULL

14. What are the names of executives with VP or Manager in their title? Use the CONCAT
function to combine the employee's first name and last name into a single field for
reporting.

SELECT CONCAT(firstName,' ',lastName) as nama, jobTitle


FROM `employees` WHERE jobTitle LIKE '%VP%' or jobTitle
LIKE '%Manager%'
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

15. Which orders have a value greater than $5,000?

SELECT productCode, quantityOrdered, priceEach,


(quantityOrdered*priceEach) as total FROM `orderdetails`
WHERE quantityOrdered * priceEach > '5000'

One to many relationship


1. Report the account representative for each customer.

SELECT concat(firstname,' ',lastname) as nama_karyawan, customername


FROM `customers` JOIN employees where
customers.salesRepEmployeeNumber=employees.employeeNumber
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

2. Report total payments for Atelier graphique.

SELECT SUM(amount) FROM `payments` JOIN `customers` USING


(customerNumber) WHERE customerName = 'Atelier graphique'

3. Report the total payments by date

SELECT paymentDate, Sum(amount) as total_pembayaran FROM


`payments` GROUP by paymentDate
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

4. Report the products that have not been sold.

SELECT productName, productCode FROM `products` p LEFT JOIN


orderdetails o USING (productCode) WHERE o.productCode is
NULL

5. List the amount paid by each customer.

SELECT customerName, SUM(amount) as total_bayar from


customers join payments using (customerNumber) GROUP BY
customerName

6. How many orders have been placed by Herkku Gifts?

SELECT sum(quantityOrdered) as jumlah_pesan FROM


`customers` JOIN `orders` USING (customerNumber) JOIN
orderdetails USING (orderNumber) WHERE customerName='Herkku
Gifts'
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

7. Who are the employees in Boston?

SELECT concat(lastname, ' ', firstname) as nama_karyawan


FROM `offices` JOIN employees USING (officeCode) WHERE city
= 'Boston'

8. Report those payments greater than $100,000. Sort the report so the customer who made
the highest payment appears first.

SELECT customername, amount FROM `payments` JOIN customers


USING (customerNumber) WHERE amount > 100000 ORDER BY
(amount) desc

9. List the value of 'On Hold' orders.

SELECT orderNumber, status, SUM(quantityOrdered*priceEach)


as total FROM orders o JOIN orderdetails d USING
(orderNumber) WHERE o.status = 'on hold' GROUP BY
orderNumber
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

10. Report the number of orders 'On Hold' for each customer.

SELECT orderNumber, status, customerName, orderdate,


SUM(quantityOrdered) as total FROM customers c JOIN orders
o USING (customerNumber) JOIN orderdetails d USING
(orderNumber) WHERE o.status = 'on hold' group BY
customerNumber
DWI PUTRI ERLINDA SARASWATI
PRA-S2 MMI
ILMU KOMPUTER UGM

Вам также может понравиться