Skip to content

Commit 6bd29cb

Browse files
committed
Add SQL JOIN examples, update resources and links in lesson notebooks.
1 parent 0d9d813 commit 6bd29cb

File tree

3 files changed

+85
-43
lines changed

3 files changed

+85
-43
lines changed

SQL-Northwind-Lesson-Exercises.ipynb

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,31 @@
343343
},
344344
{
345345
"cell_type": "markdown",
346-
"id": "0999b96c-72b1-4f3e-bf8d-73adf98d95c8",
346+
"id": "4bea2a7d-5823-4ff6-bc05-4b0c87b8e9e0",
347347
"metadata": {},
348348
"source": [
349349
"<a id='ex4'></a>\n",
350350
"### Exercise 4: Joining Tables\n",
351351
"\n",
352352
"**Objective:** Combine data from multiple tables using joins.\n",
353353
"\n",
354-
"- **Tasks:**\n",
355-
" - List all orders along with the `CompanyName` of the customer who placed each order.\n",
356-
" ```sql\n",
357-
" SELECT Orders.OrderID, Customers.CompanyName\n",
358-
" FROM Orders\n",
359-
" INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;\n",
360-
" ```\n",
361-
" - Retrieve a list of products along with their supplier's `CompanyName`.\n",
362-
" - Find all orders processed by the employee with `LastName` 'Fuller'."
354+
"Review these resources:\n",
355+
" - <a href=\"https://medium.com/swlh/the-best-visual-to-explain-sql-joins-612b95c81555\">The Best Visual To Explain SQL JOINs | by Junji Zhi | The Startup | Medium</a>\n",
356+
" - <a href=\"https://blog.codinghorror.com/a-visual-explanation-of-sql-joins/\">A Visual Explanation of SQL Joins</a>\n",
357+
" - <a href=\"https://www.atlassian.com/data/sql/sql-join-types-explained-visually\">Visualizing SQL Joins | Atlassian</a>"
358+
]
359+
},
360+
{
361+
"cell_type": "code",
362+
"execution_count": null,
363+
"id": "6d32b473-5cfd-4927-bd03-670901c7e1bb",
364+
"metadata": {},
365+
"outputs": [],
366+
"source": [
367+
"%%sql -- List all orders along with the `CompanyName` of the customer who placed each order.\n",
368+
"SELECT Orders.OrderID, Customers.CompanyName\n",
369+
"FROM Orders\n",
370+
"INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;"
363371
]
364372
},
365373
{
@@ -404,26 +412,37 @@
404412
},
405413
{
406414
"cell_type": "markdown",
407-
"id": "f5309bc4-629b-4b8a-a9b6-7a0bc44e3e6d",
415+
"id": "c6af1111-6e08-4625-8f51-fdcbbee2f81d",
408416
"metadata": {},
409417
"source": [
410418
"<a id='ex5'></a>\n",
411419
"### Exercise 5: Aggregate Functions and GROUP BY\n",
412420
"\n",
413-
"**Objective:** Use aggregate functions to summarize data.\n",
414-
"\n",
415-
"- **Tasks:**\n",
416-
" - Calculate the total number of orders.\n",
417-
" ```sql\n",
418-
" SELECT COUNT(*) AS TotalOrders FROM Orders;\n",
419-
" ```\n",
420-
" - Find the average `UnitPrice` of all products.\n",
421-
" - Determine the number of customers in each country.\n",
422-
" ```sql\n",
423-
" SELECT Country, COUNT(*) AS NumberOfCustomers\n",
424-
" FROM Customers\n",
425-
" GROUP BY Country;\n",
426-
" ```"
421+
"**Objective:** Use aggregate functions to summarize data."
422+
]
423+
},
424+
{
425+
"cell_type": "code",
426+
"execution_count": null,
427+
"id": "e49cac8d-cdf3-4e2d-baa8-6686f525e825",
428+
"metadata": {},
429+
"outputs": [],
430+
"source": [
431+
"%%sql -- Calculate the total number of orders.\n",
432+
" SELECT COUNT(*) AS TotalOrders FROM Orders;"
433+
]
434+
},
435+
{
436+
"cell_type": "code",
437+
"execution_count": null,
438+
"id": "fad21a05-07bb-4fa6-b3f9-cee5a0f188f5",
439+
"metadata": {},
440+
"outputs": [],
441+
"source": [
442+
"%%sql -- Determine the number of customers in each country.\n",
443+
"SELECT Country, COUNT(*) AS NumberOfCustomers\n",
444+
"FROM Customers\n",
445+
"GROUP BY Country;"
427446
]
428447
},
429448
{
@@ -472,24 +491,27 @@
472491
},
473492
{
474493
"cell_type": "markdown",
475-
"id": "aab1594f-5e1e-482b-89c7-1824505b0bb0",
494+
"id": "92f18575-6b60-4e35-af83-819429cc872f",
476495
"metadata": {},
477496
"source": [
478497
"<a id='ex6'></a>\n",
479498
"### Exercise 6: Advanced Joins and Subqueries\n",
480499
"\n",
481-
"**Objective:** Solve complex queries using advanced SQL techniques.\n",
482-
"\n",
483-
"**Tasks:**\n",
484-
" - List employees and the total number of orders they have processed.\n",
485-
" ```sql\n",
486-
" SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders\n",
487-
" FROM Employees\n",
488-
" LEFT JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID\n",
489-
" GROUP BY Employees.LastName;\n",
490-
" ```\n",
491-
" - Find products that have never been ordered.\n",
492-
" - Retrieve customers who have not placed any orders in 2019."
500+
"**Objective:** Solve complex queries using advanced SQL techniques."
501+
]
502+
},
503+
{
504+
"cell_type": "code",
505+
"execution_count": null,
506+
"id": "d0ee7627-5c93-45bb-a41d-8b956f71264c",
507+
"metadata": {},
508+
"outputs": [],
509+
"source": [
510+
"%%sql -- List employees and the total number of orders they have processed.\n",
511+
"SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders\n",
512+
"FROM Employees\n",
513+
"LEFT JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID\n",
514+
"GROUP BY Employees.LastName;"
493515
]
494516
},
495517
{
@@ -636,9 +658,11 @@
636658
"## Additional Resources\n",
637659
"\n",
638660
"- **SQLite Documentation:** [https://www.sqlite.org/docs.html](https://www.sqlite.org/docs.html)\n",
639-
"- **SQL Tutorial:** [W3Schools SQL Tutorial](https://www.w3schools.com/sql/)\n",
661+
"- **SQLite Command Line Reference:** [https://www.sqlite.org/cli.html](https://www.sqlite.org/cli.html)\n",
662+
"- **SQL Tutorial Cheatsheet:** [https://www.sqltutorial.org/sql-cheat-sheet/](https://www.sqltutorial.org/sql-cheat-sheet/)\n",
640663
"- **SQLite Browser Wiki:** [SQLite Browser GitHub Wiki](https://github.com/sqlitebrowser/sqlitebrowser/wiki)\n",
641-
"- **Northwind Database Schema:** [Schema Diagram](https://github.com/jpwhite3/northwind-SQLite3/blob/master/Northwind_ERD.png)"
664+
"- **Northwind SQLite Repo:** [Github Repo](https://github.com/jpwhite3/northwind-SQLite3/)\n",
665+
"- **Northwind Database Schema:** [Schema Diagram](https://github.com/jpwhite3/northwind-SQLite3/blob/main/docs/Northwind_ERD.png)"
642666
]
643667
},
644668
{

SQL-Northwind-Lesson-Overview.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@
318318
"## Additional Resources\n",
319319
"\n",
320320
"- **SQLite Documentation:** [https://www.sqlite.org/docs.html](https://www.sqlite.org/docs.html)\n",
321-
"- **SQL Tutorial:** [W3Schools SQL Tutorial](https://www.w3schools.com/sql/)\n",
321+
"- **SQLite Command Line Reference:** [https://www.sqlite.org/cli.html](https://www.sqlite.org/cli.html)\n",
322+
"- **SQL Tutorial Cheatsheet:** [https://www.sqltutorial.org/sql-cheat-sheet/](https://www.sqltutorial.org/sql-cheat-sheet/)\n",
322323
"- **SQLite Browser Wiki:** [SQLite Browser GitHub Wiki](https://github.com/sqlitebrowser/sqlitebrowser/wiki)\n",
323-
"- **Northwind Database Schema:** [Schema Diagram](https://github.com/jpwhite3/northwind-SQLite3/blob/master/Northwind_ERD.png)"
324+
"- **Northwind SQLite Repo:** [Github Repo](https://github.com/jpwhite3/northwind-SQLite3/)\n",
325+
"- **Northwind Database Schema:** [Schema Diagram](https://github.com/jpwhite3/northwind-SQLite3/blob/main/docs/Northwind_ERD.png)"
324326
]
325327
},
326328
{

Simple-SQLite-Lesson.ipynb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,26 @@
757757
"FROM people;"
758758
]
759759
},
760+
{
761+
"cell_type": "markdown",
762+
"id": "6b2b175c-725d-4f79-b04f-951086541841",
763+
"metadata": {},
764+
"source": [
765+
"<a id='resources'></a>\n",
766+
"## Additional Resources\n",
767+
"\n",
768+
"- **SQLite Documentation:** [https://www.sqlite.org/docs.html](https://www.sqlite.org/docs.html)\n",
769+
"- **SQLite Command Line Reference:** [https://www.sqlite.org/cli.html](https://www.sqlite.org/cli.html)\n",
770+
"- **SQL Tutorial Cheatsheet:** [https://www.sqltutorial.org/sql-cheat-sheet/](https://www.sqltutorial.org/sql-cheat-sheet/)\n",
771+
"- **SQLite Browser Wiki:** [SQLite Browser GitHub Wiki](https://github.com/sqlitebrowser/sqlitebrowser/wiki)\n",
772+
"- **Northwind SQLite Repo:** [Github Repo](https://github.com/jpwhite3/northwind-SQLite3/)\n",
773+
"- **Northwind Database Schema:** [Schema Diagram](https://github.com/jpwhite3/northwind-SQLite3/blob/main/docs/Northwind_ERD.png)"
774+
]
775+
},
760776
{
761777
"cell_type": "code",
762778
"execution_count": null,
763-
"id": "c0723794-cff4-47e0-aa50-505724b38436",
779+
"id": "164ab25c-9975-4cb6-aac4-639b57d2afd8",
764780
"metadata": {},
765781
"outputs": [],
766782
"source": []

0 commit comments

Comments
 (0)