SQL Practice for Autonomous University
SQL Practice for Autonomous University
Name:
=====
Enrollment:
======
Section:
====
Master:
=========
Subject:
==========
Work:
===========
AUTONOMOUS UNIVERSITY OF SANTO DOMINGO
FACULTY OF SCIENCES
DEPARTMENT OF COMPUTER SCIENCE
Practice #1 of SQL
Prepared by: Mtra. Romery Alberto M.
Given the following tables:
Client
Customer Code Client Name
1 Juan Pérez Active
2 Julio Paz Active
3 Rosa Fernández Active
4 Luis Roja Active
5 Carmen García Active
6 Roberto Ledesma Active
7 Carlos Caraballo Active
8 Juana Rosario Active
9 Pedro Jiménez Active
Invoice
Code Number Amount
Client Invoice
7 120 1,000.00
8 121 500.00
7 122 200.00
5 111 700.00
5 112 1,500.00
9 172 2,000.00
7 173 2,500.00
8 123 3,500.00
9 175 4,600.00
Receipt
Code Number Number Amount
Client Receipt Invoice
7 71 120 -100.00
7 80 120 -200.00
8 82 121 -100.00
5 91 111 -200.00
5 93 112 -300.00
5 96 112 -400.00
9 98 172 -200.00
7 99 173 -500
8 100 123 -3,500
9 101 175 -4,000
7 102 173 -600
7 103 122 -100
Carry out the following commands:
1) Create the database: PRASQL
2) Create the tables: Customer, Invoice and Receipt
3) Create the PRIMARY KEY of the tables: Client, Invoice, and Receipt
4) Create the FOREIGN KEYs for the tables: Invoice and Receipt
5) Make the necessary 'SELECT' statements to find:
[Link] amount billed by Client.
Total amount paid for each client invoice
[Link] who have more than one invoice.
[Link] invoices of Client number 5
The receipts paid by Customer number 16
[Link] amount by customer.
[Link] of receipts per client.
h. Total number of invoices
[Link] number of receipts
[Link] with the highest billed amount.
[Link] with the lowest billed amount.
The outstanding debt of the customer for each invoice
The total debt of the client
The total amount paid by the customer on each invoice
The total amount paid by the customer
Invoice
Code No.
Client Invoice Amount
7 120 1,000.00
8 121 500.00
7 122 200.00
5 111 700.00
5 112 1,500.00
9 172 2,000.00
Invoice
Code No.
Client Invoice Amount
5 110 1,300.00
5 113 2,500.00
7 114 8,200.00
7 115 5,700.00
9 116 4,500.00
9 117 2,600.00
9 118 3,500.00
9) Delete the following records in the invoice table
Invoice
Code No.
Client Invoice Amount
5 110 1,300.00
9 118 3,500.00
Invoice
Code No.
Client Invoice Amount
7 114 8,200.00
Note: You have to use the nomenclature I taught you to name tables and fields.
Code:
CREATE SCHEMA `pra_sql` DEFAULT CHARACTER SET utf8;
use pra_sql;
SELECT
t1.invoice_number,
sum([Link])
Client_Code
FROM
invoice t1
INNER JOIN client t2
ON t1.Client_Code = t2.Client_Code;
SELECT
Client_Code
t1.client_name,
[Link]
FROM
client t1
INNER JOIN invoice t2
ON t1.Client_Code = t2.Client_Code;
SELECT
t1.Client_Code
t1.customer_name
[Link]
t2.invoice_number
[Link]
FROM
client t1
INNER JOIN invoice t2
ON t1.Client_Code = 5;
SELECT
t1.Client_Code
t1.customer_names
[Link],
count(t2.invoice_number),
[Link]
FROM
client t1
INNER JOIN invoice t2
ON t1.Client_Code = t2.Client_Code
UPDATE invoice
SET amount = '34000'
WHERE Client_Code=7 and invoice_number=114;