Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*https://dev.mysql.com/doc/refman/8.0/en/creating-tables.html*/

CREATE DATABASE lab_mysql;
USE lab_mysql;

CREATE TABLE
cars(
car_vehicle_id_number VARCHAR(20),
car_manufacturer VARCHAR(20),
car_model VARCHAR(20),
car_year YEAR,
car_color VARCHAR(20)
);

CREATE TABLE
customers(
customer_id VARCHAR(20),
customer_fname VARCHAR(20),
customer_lname VARCHAR(20),
customer_phone VARCHAR(20),
customer_email VARCHAR(30),
customer_address VARCHAR(50),
customer_city VARCHAR(20),
customer_state_province VARCHAR(20),
customer_country VARCHAR(20),
customer_zipcode VARCHAR(20)
);

CREATE TABLE
salespersons(
salesperson_staff_id VARCHAR(20),
salesperson_fname VARCHAR(20),
salesperson_lname VARCHAR(20),
salesperson_store VARCHAR(20)
);

CREATE TABLE
invoices(
invoice_number VARCHAR(20),
invoice_date VARCHAR(20),
invoice_car VARCHAR(20),
invoice_customer_id VARCHAR(20),
invoice_staff_id VARCHAR(20)
);
5 changes: 5 additions & 0 deletions delete.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USE lab_mysql;

DELETE FROM cars
WHERE
car_vehicle_id_number = 'DAM41UDN3CHU2WVF6';
Binary file added diagram.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions mysql_learnings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use publications;

SELECT *
FROM employee e
INNER JOIN publishers p
on e.pub_id = p.pub_id
limit 1;


SELECT *
FROM employee e
LEFT JOIN publishers p
on e.pub_id = p.pub_id
limit 1;


SELECT *
FROM employee e
RIGHT JOIN publishers p
on e.pub_id = p.pub_id
limit 1;


/*https://stackoverflow.com/questions/12473210/mysql-outer-join-syntax-error*/
SELECT *
FROM employee e
RIGHT OUTER JOIN publishers p
ON e.pub_id = p.pub_id
LIMIT 1;

SELECT pubs.pub_name, COUNT(titles.title_id) AS Titles
FROM publications.publishers pubs
INNER JOIN publications.titles titles
ON pubs.pub_id = titles.pub_id
GROUP BY pubs.pub_name;

SELECT pubs.pub_name, COUNT(titles.title_id) AS Titles
FROM publications.publishers pubs
LEFT JOIN publications.titles titles
ON pubs.pub_id = titles.pub_id
GROUP BY pubs.pub_name;

SELECT titles.title, titles.type, titles.price, SUM(sales.qty) AS units_sold
FROM publications.sales sales
RIGHT JOIN publications.titles titles
ON sales.title_id = titles.title_id
GROUP BY titles.title, titles.type, titles.price;

SELECT *
FROM publications.employee emp
RIGHT JOIN publications.jobs job
ON emp.job_id = job.job_id
UNION
SELECT *
FROM publications.employee emp
LEFT JOIN publications.jobs job
ON emp.job_id = job.job_id;
348 changes: 348 additions & 0 deletions publications.sql

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
USE lab_mysql;

INSERT INTO
cars(
car_vehicle_id_number,
car_manufacturer,
car_model,
car_year,
car_color
)
VALUES
('3K096I98581DHSNUP', 'Volkswagen', 'Tiguan', '2019', 'Blue'),
('ZM8G7BEUQZ97IH46V', 'Peugeot', 'Rifter', '2019', 'Red'),
('RKXVNNIHLVVZOUB4M', 'Ford', 'Fusion', '2018', 'White'),
('HKNDGS7CU31E9Z7JW', 'Toyota', 'RAV4', '2018', 'Silver'),
('DAM41UDN3CHU2WVF6', 'Volvo', 'V60', '2019', 'Gray'),
('DAM41UDN3CHU2WVF6', 'Volvo', 'V60 Cross Country', '2019', 'Gray');


INSERT INTO
customers(
customer_id,
customer_fname,
customer_lname,
customer_phone,
customer_email,
customer_address,
customer_city ,
customer_state_province,
customer_country,
customer_zipcode
)
VALUES
('10001', 'Pablo', 'Picasso', '+34 636 17 63 82', '' ,'Paseo de la Chopera, 14', 'Madrid', 'Madrid', 'Spain', '28045'),
('20001', 'Abraham', 'Lincoln', '+1 305 907 7086','', '120 SW 8th St', 'Miami', 'Florida', 'United States', '33130'),
('30001', 'Napoleon', 'Bonaparte', '+33 1 79 75 40 00','', '40 Rue du Colisée', 'Paris', 'Île-de-France', 'France', '75008');


INSERT INTO
salespersons(
salesperson_staff_id,
salesperson_fname,
salesperson_lname,
salesperson_store
)
VALUES
('00001', 'Petey', 'Cruiser', 'Madrid'),
('00002', 'Anna', 'Sthesia','Barcelona'),
('00003', 'Paul', 'Molive', 'Berlin'),
('00004', 'Gail', 'Forcewind', 'Paris'),
('00005', 'Paige', 'Turner', 'Mimia'),
('00006', 'Bob', 'Frapples', 'Mexico City'),
('00007', 'Walter', 'Melon', 'Amsterdam'),
('00008', 'Shonda', 'Leer', 'São Paulo');

INSERT INTO
invoices(
invoice_number,
invoice_date,
invoice_car,
invoice_customer_id,
invoice_staff_id
)
VALUES
('852399038', '22-08-2018', '0', '1', '3'),
('731166526', '31-12-2018', '3', '0', '5'),
('271135104', '22-01-2019', '2', '2', '7');
25 changes: 25 additions & 0 deletions update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
USE lab_mysql;

UPDATE salespersons
SET
salesperson_store = 'Miami'
WHERE
salesperson_staff_id = '00005';

UPDATE customers
SET
customer_email = 'ppicasso@gmail.com'
WHERE
customer_lname = 'Picasso';

UPDATE customers
SET
customer_email = 'lincoln@us.gov'
WHERE
customer_lname = 'Lincoln';

UPDATE customers
SET
customer_email = 'hello@napoleon.me'
WHERE
customer_lname = 'Bonaparte';