@@ -1,15 +0,0 @@ | |||
Header element – The <header> element defines content that should be considered the introductory information of a page or section. | |||
Nav element – Main navigation menu links would all be placed in a <nav> tag. But sub navigation menus elsewhere on the page could also get one. | |||
Main tag – The body of a page should go in the <main> tag – not sidebars and main navigation. There should be only one per page. | |||
Article element – The <article> element defines self-contained content that could stand independently of the page or site it’s on. For example, a blog post. | |||
Section element – Using <section> is a way of grouping together nearby content of a similar theme. A section tag differs to an article tag because it isn’t necessarily self-contained. | |||
Aside element – An <aside> element defines content that’s less important. It’s often used for sidebars – areas that add complementary but not vital information. | |||
Footer element – You would use <footer> at the base of a page or section. It might include contact information and some site navigation. |
@@ -1,4 +0,0 @@ | |||
Select * | |||
FROM vendors | |||
INNER JOIN invoices | |||
ON vendors.vendors_id = invoice.vendors_id; |
@@ -1,3 +0,0 @@ | |||
Select * | |||
FROM vendors | |||
INNER JOIN invoices; |
@@ -1,9 +0,0 @@ | |||
SELECT | |||
vendor_name, | |||
invoice_number, | |||
invoice_date, | |||
invoice_total - payment_total - credit_total AS balance_due | |||
From vendors JOIN invoices | |||
on vendors.vendors_id = invoice.vendors_id | |||
WHERE invoice_total - payment_total - credit_total <> | |||
ORDER BY vendor_name ASC; |
@@ -1,9 +0,0 @@ | |||
SELECT | |||
vendor_name, | |||
invoice_number, | |||
invoice_date, | |||
invoice_total - payment_total - credit_total AS balance_due | |||
From vendors v, | |||
invoices i | |||
WHERE invoice_total IS NULL | |||
ORDER BY vendor_name ASC; |
@@ -1,6 +0,0 @@ | |||
SELECT vendor_name, | |||
default_account_number AS default_account, | |||
account_description AS description | |||
FROM vendors v JOIN general_ledger_accounts g | |||
ON vendors.default_account_number = general_ledger_accounts.default_account_number | |||
ORDER BY default_account, vendor_name; |
@@ -1,6 +0,0 @@ | |||
SELECT vendor_name, | |||
default_account_number AS default_account, | |||
account_description AS description | |||
FROM vendors v, | |||
general_ledger_accounts g | |||
ORDER BY default_account, vendor_name; |
@@ -1,13 +0,0 @@ | |||
SELECT vendor_name, | |||
invoice_date, | |||
invoice_number, | |||
invoice_sequence AS li_sequence, | |||
line_item_amount AS li_amount | |||
FROM vendors v JOIN invoices i, | |||
ON v.vendors_id = i.verdors_id | |||
JOIN Invoice_Line_Items li | |||
ON i.invoice_id = li.invoice.id | |||
ORDER BY vendor_name, | |||
invoice_date, | |||
invoice_number, | |||
invoice_sequence; |
@@ -1,12 +0,0 @@ | |||
SELECT vendor_name, | |||
invoice_date, | |||
invoice_number, | |||
invoice_sequence AS li_sequence, | |||
line_item_amount AS li_amount | |||
FROM vendors v, | |||
invoices i, | |||
Invoice_Line_Items l | |||
ORDER BY vendor_name, | |||
invoice_date, | |||
invoice_number, | |||
invoice_sequence; |
@@ -1,6 +0,0 @@ | |||
SELECT vendor_id, | |||
concat(vendor_contact_first_name, vendor_contact_last_name) AS contact_name | |||
FROM vendor_contacts v JOIN vendor_contacts v1 | |||
ON v.vendor_id <> v1.vendors_id v1 | |||
AND v.vendor_contact_last_name = v1.vendor_contact_last_name | |||
ORDER BY v.vendor_contact_last_name ASC; |
@@ -1,6 +0,0 @@ | |||
SELECT vendor_id, | |||
vendor_name, | |||
concat(vendor_contact_first_name, vendor_contact_last_name) AS contact_name | |||
FROM vendor v | |||
WHERE vendor_id = vendor_contact_last_name | |||
ORDER BY vendor_contact_last_name; |
@@ -1,7 +0,0 @@ | |||
SELECT account_number, | |||
account_description, | |||
invoice_id | |||
FROM invoice_line_items i LEFT OUTER JOIN general_ledger_accounts g | |||
ON i.account_number = g.account_number | |||
WHERE invoice_id = NULL | |||
ORDER BY g.account_number ASC; |
@@ -1,10 +0,0 @@ | |||
SELECT vendor_name, vendor_state | |||
FROM vendors v1 JOIN vendors v2 | |||
ON v1.vendor_name = v2.vendor_name | |||
WHERE v1.vendor_state = "CA" otherwise v1.vendor_state = "OUTSIDE CA" | |||
UNION | |||
SELECT vendor_name, vendor_state | |||
FROM vendors v1 JOIN vendors v2 | |||
ON v1.vendor_name = v2.vendor_name | |||
WHERE v1.vendor_state = "CA" otherwise v1.vendor_state = "OUTSIDE CA" | |||
ORDER BY vendor_name ASC; |
@@ -1,4 +0,0 @@ | |||
INSERT INTO terms | |||
(terms_id,terms_description,terms_due_days) | |||
VALUES | |||
(6,'Net due 120 days',120); |
@@ -1,2 +0,0 @@ | |||
UPDATE terms | |||
SET terms_description = 'Net due 125 days'; |
@@ -1,3 +0,0 @@ | |||
use ap; | |||
DELETE FROM terms | |||
WHERE terms_id = 6; |
@@ -1,2 +0,0 @@ | |||
INSERT INTO invoices VALUES | |||
(DEFAULT, 32, 'AX-014-027', '2018-01-08', 454.58, 0, 0, 2,'2018-08-31', NULL) |
@@ -1,3 +0,0 @@ | |||
INSERT INTO invoices_line_items VALUES | |||
(123,1, 160, 180.23, 'HARD DRIVE'), | |||
(123,2, 527, 254.35, 'Exchange Server update'); |
@@ -1,6 +0,0 @@ | |||
use ap; | |||
select * from invoices | |||
UPDATE invoices | |||
SET credit_total = invoice_total * 0.1 | |||
payement_total = invoice_total - credit_total | |||
WHERE invoice_id = ''; |
@@ -1,4 +0,0 @@ | |||
use ap; | |||
UPDATE vendors | |||
SET account_number = 403 | |||
WHERE vendor_id = 44; |
@@ -1 +0,0 @@ | |||
select * from invoices |
@@ -1,89 +1,77 @@ | |||
# How_to_retrieve_data_from_two_or_more_tables | |||
# How to retrieve data from a single table | |||
###Exercise 1 | |||
### Exercise 1 | |||
Write a SELECT statement that returns all columns from the Vendors table inner-joined with all columns from the Invoices table. This should return 114 rows. Hint: You can use an asterisk (*) to select the columns from both tables. | |||
Write a SELECT statement that returns three columns from the Vendors table: vendor_name, vendor_contact_last_name, and vendor_contact_first_name. Then, run this statement to make sure it works correctly. | |||
###Exercise 2 | |||
Add an ORDER BY clause to this statement that sorts the result set by last name and then first name, both in ascending sequence. Then, run this state‐ment again to make sure it works correctly. | |||
Write a SELECT statement that returns these four columns: | |||
This is a good way to build and test a statement, one clause at a time. | |||
**vendor_name** (The vendor_name column from the Vendors table) | |||
**invoice_number** (The invoice_number column from the Invoices table) | |||
**invoice_date** (The invoice_date column from the Invoices table) | |||
**balance_due** (The invoice_total column minus the payment_total and credit_total columns from the Invoices table) | |||
Use these aliases for the tables: v for Vendors and i for Invoices. | |||
### Exercise 2 | |||
Return one row for each invoice with a non-zero balance. This should return 11 rows. | |||
Write a SELECT statement that returns one column from the Vendors table named full_name that joins the vendor_contact_last_name and vendor_contact_first_name columns. Format this column with the last name, a comma, a space, and the first name like this: | |||
Sort the result set by vendor_name in ascending order. | |||
Doe, John | |||
###Exercise 3 | |||
Sort the result set by last name and then first name in ascending sequence. Return only the contacts whose last name begins with the letter A, B, C, or E. This should retrieve 41 rows. | |||
Write a SELECT statement that returns these three columns: | |||
### Exercise 3 | |||
**vendor_name** (The vendor_name column from the Vendors table) | |||
**default_account** (The default_account_number column from the Vendors table) | |||
**description** (The account_description column from the General_Ledger_Accounts table) | |||
Write a SELECT statement that returns these column names and data from the Invoices table: | |||
Return one row for each vendor. This should return 122 rows. | |||
Due Date (The invoice_due_date column) | |||
Invoice Total (The invoice_total column) | |||
10% (10% of the value of invoice_total) | |||
Plus 10% (The value of invoice_total plus 10%) | |||
Sort the result set by account_description and then by vendor_name. | |||
Return only the rows with an invoice total that’s greater than or equal to 500 and less than or equal to 1000. This should retrieve 12 rows. | |||
###Exercise 4 | |||
Sort the result set in descending sequence by invoice_due_date. | |||
Write a SELECT statement that returns these five columns: | |||
### Exercise 4 | |||
**vendor_name** (The vendor_name column from the Vendors table) | |||
**invoice_date** (The invoice_date column from the Invoices table) | |||
**invoice_number** (The invoice_number column from the Invoices table) | |||
**li_sequence** (The invoice_sequence column from the Invoice_Line_Items table) | |||
**li_amount** (The line_item_amount column from the Invoice_Line_Items table) | |||
Write a SELECT statement that returns these columns from the Invoices table: | |||
Use aliases for the tables. This should return 118 rows. | |||
invoice_number (The invoice_number column) | |||
invoice_total (The invoice_total column) | |||
payment_credit_total (Sum of the payment_total and credit_total columns) | |||
balance_due (The invoice_total column minus the payment_total and credit_total columns) | |||
Sort the final result set by vendor_name, invoice_date, invoice_number, and invoice_sequence. | |||
###Exercise 5 | |||
Return only invoices that have a balance due that’s greater than $50. | |||
Write a SELECT statement that returns three columns: | |||
Sort the result set by balance due in descending sequence. | |||
**vendor_id** (The vendor_id column from the Vendors table) | |||
**vendor_name** (The vendor_name column from the Vendors table) | |||
**contact_name** (A concatenation of the vendor_contact_first_name and vendor_contact_last_name columns with a space between) | |||
Use the LIMIT clause so the result set contains only the rows with the 5 largest balances. | |||
Return one row for each vendor whose contact has the same last name as another vendor’s contact. This should return 2 rows. | |||
### Exercise 5 | |||
*Hint: Use a self-join to check that the vendor_id columns aren’t equal but the vendor_contact_last_name columns are equal.* | |||
Write a SELECT statement that returns these columns from the Invoices table: | |||
Sort the result set by vendor_contact_last_name. | |||
invoice_number (The invoice_number column) | |||
invoice_date (The invoice_date column) | |||
balance_due (The invoice_total column minus the payment_total and credit_total columns) | |||
payment_date (The payment_date column) | |||
###Exercise 6 | |||
Return only the rows where the payment_date column contains a null value. This should retrieve 11 rows. | |||
Write a SELECT statement that returns these three columns: | |||
### Exercise 6 | |||
**account_number** (The account_number column from the General_Ledger_Accounts table) | |||
**account_description** (The account_description column from the General_Ledger_Accounts table) | |||
**invoice_id** (The invoice_id column from the Invoice_Line_Items table) | |||
Write a SELECT statement without a FROM clause that uses the CURRENT_DATE function to return the current date in its default format. | |||
Return one row for each account number that has never been used. This should return 54 rows. | |||
Use the DATE_FORMAT function to format the current date in this format: mm-dd-yyyy | |||
*Hint: Use an outer join and only return rows where the invoice_id column contains a null value.* | |||
This displays the month, day, and four‐digit year of the current date. | |||
Remove the invoice_id column from the SELECT clause. | |||
Give this column an alias of current_date. To do that, you must enclose the alias in quotes since that name is already used by the CURRENT_DATE function. | |||
Sort the final result set by the account_number column. | |||
###Exercise 7 | |||
Use the UNION operator to generate a result set consisting of two columns from the Vendors table: vendor_name and vendor_state. | |||
If the vendor is in California, the vendor_state value should be “CA”; otherwise, the vendor_state value should be “Outside CA.” | |||
Sort the final result set by vendor_name. | |||
### Exercise 7 | |||
Write a SELECT statement without a FROM clause that creates a row with these columns: | |||
starting_principal (Starting principal of $50,000) | |||
interest (6.5% of the principal) | |||
principal_plus_interest (The principal plus the interest) | |||
To calculate the third column, add the expressions you used for the first two columns. |
@@ -0,0 +1,4 @@ | |||
SELECT concat(vendor_contact_last_name, ' ',vendor_contact_first_name) AS full_name | |||
FROM vendors | |||
WHERE vendor_contact_last_name REGEXP 'A' OR 'B' OR 'C' OR 'E' | |||
ORDER BY vendor_contact_last_name ASC; |
@@ -0,0 +1,7 @@ | |||
USE AP; | |||
SELECT invoice_number, vendor_name, invoice_due_date, | |||
invoice_total - payment_total - credit_total AS balance_due | |||
FROM vendors v JOIN invoices i | |||
ON v.vendor_id = i.vendor_id | |||
WHERE invoice_total - payment_total - credit_total > 0 | |||
ORDER BY invoice_due_date DESC; |
@@ -0,0 +1,6 @@ | |||
USE AP; | |||
SELECT vendor_name, customer_last_name, customer_first_name, | |||
vendor_state AS state, vendor_city AS city | |||
FROM vendors v JOIN om.customers c | |||
ON v.vendor_zip_code = c.customer_zip | |||
ORDER BY state, city ASC; |
@@ -0,0 +1,10 @@ | |||
USE AP; | |||
SELECT vendor_name, invoice_number, invoice_date, account_description, line_item_amount | |||
FROM vendors v JOIN invoices i | |||
ON v.vendor_id = i.vendor_id | |||
JOIN invoice_line_items li | |||
ON i.invoice_id = li.invoice_id | |||
JOIN general_ledger_accounts ge | |||
on li.account_number = ge.account_number | |||
WHERE invoice_total - payment_total - credit_total > 0 | |||
ORDER BY vendor_name, line_item_amount DESC; |
@@ -0,0 +1,5 @@ | |||
USE AP; | |||
SELECT vendor_name, invoice_number, invoice_total | |||
FROM vendors v LEFT JOIN invoices i | |||
ON v.vendor_id = i.vendor_id | |||
ORDER BY vendor_name ASC |
@@ -0,0 +1,6 @@ | |||
USE ex; | |||
SELECT department_name, d.department_name, last_name | |||
FROM departments d LEFT JOIN employees e | |||
ON d.department_number = e.department_number | |||
ORDER BY department_name ASC; | |||
@@ -0,0 +1,7 @@ | |||
USE ex; | |||
SELECT department_name, last_name, project_number | |||
FROM departments d JOIN employees e | |||
ON d.department_number = e.department_number | |||
LEFT JOIN projects p | |||
ON e.employee_id = p.employee_id | |||
ORDER BY department_name, last_name ASC; |
@@ -0,0 +1,6 @@ | |||
USE ex; | |||
SELECT department_name, last_name, project_number | |||
FROM departments | |||
NATURAL JOIN employees | |||
LEFT JOIN projects USING (employee_id) | |||
ORDER BY department_name ASC; |
@@ -0,0 +1,6 @@ | |||
USE ex; | |||
SELECT departments.department_number, department_name, employee_id, last_name | |||
FROM departments,employees | |||
ORDER BY departments.department_number ASC; | |||
/* a cross join */ |
@@ -0,0 +1,11 @@ | |||
USE ex; | |||
SELECT 'Active' AS source, invoice_number, invoice_date, invoice_total | |||
FROM active_invoices | |||
WHERE invoice_date >= '2018_06_01' | |||
UNION | |||
SELECT 'Paid' AS source, invoice_number, invoice_date, invoice_total | |||
FROM paid_invoices | |||
WHERE invoice_date >= '2018_06_01' | |||
ORDER BY invoice_total DESC; | |||
/* union |
@@ -0,0 +1,10 @@ | |||
USE AP; | |||
SELECT 'Active' AS source, invoice_number, invoice_date, invoice_total | |||
FROM invoices | |||
WHERE invoice_date >= '2018_06_01' | |||
UNION | |||
SELECT 'Paid' AS source, invoice_number, invoice_date, invoice_total | |||
FROM invoices | |||
WHERE invoice_date >= '2018_06_01' | |||
ORDER BY invoice_total DESC; |
@@ -0,0 +1,3 @@ | |||
SELECT vendor_name, vendor_contact_last_name, vendor_contact_first_name | |||
FROM vendors | |||
ORDER BY vendor_contact_last_name, vendor_contact_first_name ASC; |
@@ -0,0 +1,21 @@ | |||
USE AP; | |||
SELECT invoice_number, vendor_name, '33% PAYMENT' AS payment_type, | |||
invoice_total AS total, invoice_total * 0.333 AS payment | |||
FROM invoices JOIN vendors | |||
ON invoices.vendor_id = vendors.vendor_id | |||
WHERE invoice_total > 10000 | |||
UNION | |||
SELECT invoice_number, vendor_name, '50% PAYMENT' AS payment_type, | |||
invoice_total AS total, invoice_total * 0.500 AS payment | |||
FROM invoices JOIN vendors | |||
ON invoices.vendor_id = vendors.vendor_id | |||
WHERE invoice_total BETWEEN 500 AND 10000 | |||
UNION | |||
SELECT invoice_number, vendor_name, 'FULL PAYMENT' AS payment_type, | |||
invoice_total AS total, invoice_total AS payment | |||
FROM invoices JOIN vendors | |||
ON invoices.vendor_id = vendors.vendor_id | |||
WHERE invoice_total < 500 | |||
ORDER BY payment_type, vendor_name, invoice_number; | |||
/* 3 unions van 4 tabellen |
@@ -0,0 +1,9 @@ | |||
11 | |||
32020.42 | |||
USE AP; | |||
SELECT COUNT(*) AS number_of_invoices, | |||
SUM(invoice_total - payment_total - credit_total) AS total_due | |||
FROM invoices | |||
WHERE invoice_total - payment_total - credit_total > 0; |
@@ -0,0 +1,12 @@ | |||
After 1/1/2018 | |||
114 | |||
37966.19 | |||
6.00 | |||
use ap; | |||
SELECT 'After 1/1/2018' AS selection_date, | |||
COUNT(*) AS number_of_invoices, | |||
MAX(invoice_total) AS highest_invoice_total, | |||
MIN(invoice_total) AS lowest_invoice_total | |||
FROM invoices | |||
WHERE invoice_date > '01/01/2018'; |
@@ -0,0 +1,4 @@ | |||
SELECT invoice_number, invoice_date, invoice_total | |||
FROM invoices | |||
WHERE invoice_date BETWEEN '2018-06-01' AND '2018-06-30' | |||
ORDER BY invoice_date DESC; |
@@ -0,0 +1,3 @@ | |||
SELECT invoice_number,invoice_date,invoice_total | |||
FROM invoices | |||
ORDER BY invoice_total desc; |
@@ -0,0 +1,3 @@ | |||
SELECT invoice_id,invoice_total, credit_total + payment_total AS total | |||
FROM invoices | |||
WHERE invoice_id = 18; |
@@ -0,0 +1,3 @@ | |||
SELECT invoice_number, invoice_date, invoice_total | |||
FROM invoices | |||
WHERE invoice_total > 50000; |
@@ -0,0 +1,3 @@ | |||
SELECT DISTINCT vendor_state, vendor_city | |||
FROM vendors | |||
ORDER BY vendor_state DESC; |
@@ -0,0 +1,5 @@ | |||
use ap; | |||
SELECT invoice_number, vendor_name | |||
FROM vendors INNER JOIN invoices | |||
ON vendors.vendor_id = invoices.vendor_id | |||
ORDER BY invoice_number; |
@@ -0,0 +1,7 @@ | |||
USE AP; | |||
SELECT invoice_number, vendor_name, invoice_due_date, | |||
invoice_total - payment_total - credit_total AS balance_due | |||
FROM vendors v JOIN invoices i | |||
ON v.vendor_id = i.vendor_id | |||
WHERE invoice_total - payment_total - credit_total > 0 | |||
ORDER BY invoice_due_date DESC; |