From 3ed87f5ac78f37370e5091e9450ba21f91c1c312 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Mon, 21 Feb 2022 11:26:11 -0600 Subject: [PATCH 1/5] commiting first excercise --- .gitignore | 1 + non_usa_customers.sql | 2 ++ project_notes.md | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 .gitignore create mode 100644 non_usa_customers.sql create mode 100644 project_notes.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c76d08a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +projectnotes.md* diff --git a/non_usa_customers.sql b/non_usa_customers.sql new file mode 100644 index 0000000..1aaf752 --- /dev/null +++ b/non_usa_customers.sql @@ -0,0 +1,2 @@ +SELECT CustomerId, FirstName, Country FROM CUSTOMER +WHERE COUNTRY != 'USA'; \ No newline at end of file diff --git a/project_notes.md b/project_notes.md new file mode 100644 index 0000000..ddaa6bc --- /dev/null +++ b/project_notes.md @@ -0,0 +1,26 @@ +# Project Notes - SQL Interlude - U + +## Questions +### How to use NOT in queries +Why does + +``` +SELECT * FROM CUSTOMER +WHERE COUNTRY NOT LIKE 'USA'; +``` + +work and + +``` +SELECT * FROM CUSTOMER +WHERE COUNTRY NOT 'USA'; +``` +does not work? + +### Answer +To avoid using like +`WHERE NOT customer.country = "USA";`
+or
+`WHERE NOT != "USA";`
+ +are valid ways of forming the query. \ No newline at end of file From 4dca957222831a96b4af6435129a3c789e688f7e Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Mon, 21 Feb 2022 12:00:52 -0600 Subject: [PATCH 2/5] saving progress before lunch --- brazil_customers.sql | 2 ++ brazil_customers_invoices.sql | 4 ++++ project_notes.md | 11 ++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 brazil_customers.sql create mode 100644 brazil_customers_invoices.sql diff --git a/brazil_customers.sql b/brazil_customers.sql new file mode 100644 index 0000000..2c9a2a2 --- /dev/null +++ b/brazil_customers.sql @@ -0,0 +1,2 @@ +SELECT FirstName, LastName, Country FROM CUSTOMER +WHERE Country = 'Brazil'; \ No newline at end of file diff --git a/brazil_customers_invoices.sql b/brazil_customers_invoices.sql new file mode 100644 index 0000000..7a4572b --- /dev/null +++ b/brazil_customers_invoices.sql @@ -0,0 +1,4 @@ +SELECT + CONCAT_WS("-", "FirstName", "LastName") AS FULLNAME, CustomerId, InvoiceId, InvoiceDate, BillingCountry +FROM + Customer, Invoice diff --git a/project_notes.md b/project_notes.md index ddaa6bc..b22b748 100644 --- a/project_notes.md +++ b/project_notes.md @@ -1,4 +1,4 @@ -# Project Notes - SQL Interlude - U +# Project Notes - SQL Interlude - Chinook ## Questions ### How to use NOT in queries @@ -18,9 +18,14 @@ WHERE COUNTRY NOT 'USA'; does not work? ### Answer -To avoid using like +To avoid using `LIKE`
+ `WHERE NOT customer.country = "USA";`
or
`WHERE NOT != "USA";`
-are valid ways of forming the query. \ No newline at end of file +are valid ways of forming the query. + +## Resources +[How to concatenate columns in SQL - CONCAT_WS()](https://www.w3schools.com/sql/func_mysql_concat_ws.asp) + From 54bd9db8251ecba2e7d25cd0d86f033fddd35366 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Mon, 21 Feb 2022 13:52:12 -0600 Subject: [PATCH 3/5] savin completed problem 3 --- brazil_customers_invoices.sql | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/brazil_customers_invoices.sql b/brazil_customers_invoices.sql index 7a4572b..810a065 100644 --- a/brazil_customers_invoices.sql +++ b/brazil_customers_invoices.sql @@ -1,4 +1,12 @@ SELECT - CONCAT_WS("-", "FirstName", "LastName") AS FULLNAME, CustomerId, InvoiceId, InvoiceDate, BillingCountry + Customer.FirstName, Customer.LastName, Invoice.InvoiceId, Invoice.InvoiceDate, Invoice.BillingCountry FROM - Customer, Invoice + Invoice +INNER JOIN + Customer +ON + Invoice.CustomerId = Customer.CustomerId +WHERE + Invoice.BillingCountry = 'Brazil' +ORDER BY + LastName ASC; \ No newline at end of file From 19543619d43a423acebf47335ffcd19a09d5350a Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Mon, 21 Feb 2022 14:24:38 -0600 Subject: [PATCH 4/5] saving completed problem 5 --- sales_agents.sql | 8 ++++++++ unique_invoice_countries.sql | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 sales_agents.sql create mode 100644 unique_invoice_countries.sql diff --git a/sales_agents.sql b/sales_agents.sql new file mode 100644 index 0000000..b6512c4 --- /dev/null +++ b/sales_agents.sql @@ -0,0 +1,8 @@ +SELECT DISTINCT + EMPLOYEE.FirstName, EMPLOYEE.LastName +FROM + EMPLOYEE +INNER JOIN + Customer +ON + EMPLOYEE.EmployeeId = Customer.SupportRepId; \ No newline at end of file diff --git a/unique_invoice_countries.sql b/unique_invoice_countries.sql new file mode 100644 index 0000000..d74a2b4 --- /dev/null +++ b/unique_invoice_countries.sql @@ -0,0 +1,5 @@ +SELECT DISTINCT + BillingCountry +FROM + INVOICE; + From 7d08c85c2ee404042811956c52ef75e45d7df8bf Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Mon, 21 Feb 2022 15:02:27 -0600 Subject: [PATCH 5/5] saving work from ch 6 --- sales_agent_invoices.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sales_agent_invoices.sql diff --git a/sales_agent_invoices.sql b/sales_agent_invoices.sql new file mode 100644 index 0000000..7741fff --- /dev/null +++ b/sales_agent_invoices.sql @@ -0,0 +1,14 @@ +SELECT + EMPLOYEE.FirstName, EMPLOYEE.LastName, InvoiceId +FROM + Employee +INNER JOIN + INVOICE +ON + CUSTOMER.CustomerId = INVOICE.CustomerId +INNER JOIN + Customer +ON + Customer.SupportRepId = Employee.EmployeeId +ORDER BY + InvoiceId ASC; \ No newline at end of file