From 3098bac01f4781b3185ccf7f2b131f66daa14029 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Wed, 8 Oct 2025 13:53:47 -0500 Subject: [PATCH 01/22] Update SQL-Part-1-Exercises.ipynb --- .../exercises/SQL-Part-1-Exercises.ipynb | 71 ++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/sql-part-1/exercises/SQL-Part-1-Exercises.ipynb b/sql-part-1/exercises/SQL-Part-1-Exercises.ipynb index 98cb722e2..78cab615a 100644 --- a/sql-part-1/exercises/SQL-Part-1-Exercises.ipynb +++ b/sql-part-1/exercises/SQL-Part-1-Exercises.ipynb @@ -68,7 +68,10 @@ }, "outputs": [], "source": [ - "-- Code Here:" + "use BooksDB\n", + "select top 1000*\n", + "from weddings\n", + "\n" ] }, { @@ -88,7 +91,9 @@ }, "outputs": [], "source": [ - "-- Code Here:" + "use BooksDB\n", + "select 10000\n", + "from title\n" ] }, { @@ -108,7 +113,10 @@ }, "outputs": [], "source": [ - "-- Code Here:" + "use BooksDB\n", + "select original_publication_year\n", + "WHERE original_publication_year < 1800\n", + "\n" ] }, { @@ -127,9 +135,51 @@ } }, "outputs": [], - "source": [ - "-- Code Here:" - ] + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "sql" + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "sql" + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "sql" + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "sql" + } + }, + "outputs": [], + "source": [] }, { "cell_type": "markdown", @@ -148,7 +198,10 @@ }, "outputs": [], "source": [ - "-- Code Here:" + "use BooksDB\n", + "select language_id\n", + "where language_id = \"eng\"\n", + "\n" ] }, { @@ -168,7 +221,9 @@ }, "outputs": [], "source": [ - "-- Code Here:" + "use BooksDB\n", + "select original_publication_year\n", + "where original_publication_year > 1914 and original_publication_year < 1921" ] }, { From a994549c690d00676ba26d3abac3ff31c3a1105e Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 9 Oct 2025 18:57:28 -0500 Subject: [PATCH 02/22] Update SQL-Part-2-Studio.ipynb --- sql-part-2/studio/SQL-Part-2-Studio.ipynb | 362 ++++++++++++---------- 1 file changed, 199 insertions(+), 163 deletions(-) diff --git a/sql-part-2/studio/SQL-Part-2-Studio.ipynb b/sql-part-2/studio/SQL-Part-2-Studio.ipynb index f335becb6..527dbf6d4 100644 --- a/sql-part-2/studio/SQL-Part-2-Studio.ipynb +++ b/sql-part-2/studio/SQL-Part-2-Studio.ipynb @@ -1,26 +1,11 @@ { - "metadata": { - "kernelspec": { - "name": "SQL", - "display_name": "SQL", - "language": "sql" - }, - "language_info": { - "name": "sql", - "version": "" - }, - "extensions": { - "vscode": { - "version": 1, - "views": [] - } - } - }, - "nbformat_minor": 2, - "nbformat": 4, "cells": [ { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "bbaa021d-dbcb-4f90-a05f-f280d524589a" + }, "source": [ "# Lesson 11: SQL Part 2 Studio\n", "\n", @@ -31,364 +16,415 @@ "**The Dataset:** \n", "\n", "> We will be working with the **BooksDB dataset** from Lesson 10.  You should already have access to it." - ], - "metadata": { - "azdata_cell_guid": "bbaa021d-dbcb-4f90-a05f-f280d524589a" - }, - "attachments": {} + ] }, { "cell_type": "markdown", - "source": [ - "## The Questions:" - ], "metadata": { "azdata_cell_guid": "bfc33995-70d4-4403-a870-39244e5e9727" - } + }, + "source": [ + "## The Questions:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "29e63840-f200-4b1b-9239-4dc60a402c1d" + }, "source": [ "1.  Create a query that returns the longest title in the dataset.  We can do this in two steps.\n", "\n", "> A. Create a query that returns the length of the longest title.\n", "> \n", "> B. Create a query that uses the length you found in step A to find the longest title." - ], - "metadata": { - "azdata_cell_guid": "29e63840-f200-4b1b-9239-4dc60a402c1d" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 1, "metadata": { "azdata_cell_guid": "fc1a211d-ea4e-446a-bbf8-e31499c50aba" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.111" + "text/html": [ + "Total execution time: 00:00:00.111" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 1 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "5de64491-7324-44ce-bda4-e22b07229854" + }, "source": [ "2.  Use what you learned in question 1 to find the shortest author name.  \n", "\n", "> A. Create a query that returns the length of the shortest author.\n", "> \n", "> B. Create a query that returns the shortest author's name." - ], - "metadata": { - "azdata_cell_guid": "5de64491-7324-44ce-bda4-e22b07229854" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 2, "metadata": { "azdata_cell_guid": "61423c75-cb55-470f-b062-a1901d3da67c" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.053" + "text/html": [ + "Total execution time: 00:00:00.053" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 2 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "97f50346-9729-4d1b-926c-e1b53c5c5e68" + }, "source": [ "3\\. How many titles contain the word \"The\"?  \n", "\n", " \n", "\n", "> A. Is there a difference between the number of titles that use \"The\" or \"the\"?" - ], - "metadata": { - "azdata_cell_guid": "97f50346-9729-4d1b-926c-e1b53c5c5e68" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 3, "metadata": { "azdata_cell_guid": "f58433db-eb3b-46e0-bb4d-85ca52d359b5" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.053" + "text/html": [ + "Total execution time: 00:00:00.053" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 3 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "4.  How many authors' names _start_ with 'Z'?" - ], "metadata": { "azdata_cell_guid": "e0d89eca-410d-4e29-82ca-265b79c73fea" }, - "attachments": {} + "source": [ + "4.  How many authors' names _start_ with 'Z'?" + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 4, "metadata": { "azdata_cell_guid": "850f04c8-458a-4cfb-95c4-4dbb7a3d63d0" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.072" + "text/html": [ + "Total execution time: 00:00:00.072" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 4 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "7066afeb-79d2-4e7f-b497-cbde17655b19" + }, "source": [ "5\\. How many books have been identified as printed in a language other than English?  There are four language codes for English: 'en', 'eng', 'en-US', and 'en-UK'.  Use LEFT to answer the question.  (Do not use the wildcard)\n", "\n", "You might want to use one of these [comparison operators](https://docs.microsoft.com/en-us/sql/t-sql/language-elements/comparison-operators-transact-sql?view=sql-server-ver15)." - ], - "metadata": { - "azdata_cell_guid": "7066afeb-79d2-4e7f-b497-cbde17655b19" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 5, "metadata": { "azdata_cell_guid": "5a85f5ae-dd59-4fa1-828a-c63fa330ff7f" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.051" + "text/html": [ + "Total execution time: 00:00:00.051" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 5 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "6\\. Retry question 5 using SUBSTRING." - ], "metadata": { "azdata_cell_guid": "93153cd1-ecea-4e4b-87f5-2214993a7291" }, - "attachments": {} + "source": [ + "6\\. Retry question 5 using SUBSTRING." + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 6, "metadata": { "azdata_cell_guid": "7756ae02-4ec2-4456-b3a7-c3604bf07e26" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:02.896" + "text/html": [ + "Total execution time: 00:00:02.896" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 6 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "c8124542-ea76-4153-96ef-f4db908fbd6c" + }, "source": [ "7.  Create a column that returns the title, authors, and language codes.  Concatenate these elements so that they return in the following way: title by authors in language\\_code language.\n", "\n", "> A.  Check each selected column to see where any values are NULL.  Did any of the columns contain NULL values?  If so, which one?" - ], - "metadata": { - "azdata_cell_guid": "c8124542-ea76-4153-96ef-f4db908fbd6c" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 7, "metadata": { "azdata_cell_guid": "26705af1-6191-48b9-b649-7bc93cad102d" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.048" + "text/html": [ + "Total execution time: 00:00:00.048" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 7 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "17fd76a8-afa7-4d86-a200-2902d7310a2b" + }, "source": [ "8.  Update the query in question 7 using COALESCE to change the language code values from NULL to 'unknown'.\n", "\n", "> A.  Has this changed the language\\_code  where the values are NULL?" - ], - "metadata": { - "azdata_cell_guid": "17fd76a8-afa7-4d86-a200-2902d7310a2b" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 8, "metadata": { "azdata_cell_guid": "f9694996-4545-48b9-9981-325b5c590570" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.057" + "text/html": [ + "Total execution time: 00:00:00.057" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 8 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "57b87290-135f-478d-bf1c-2262759f8da5" + }, "source": [ "9\\. Revisit question 7 using ISNULL instead of COALESCE.\n", "\n", "> A.  Has this changed the language\\_code  where the values are NULL?" - ], - "metadata": { - "azdata_cell_guid": "57b87290-135f-478d-bf1c-2262759f8da5" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 9, "metadata": { "azdata_cell_guid": "a9670717-6dc6-4685-9f62-7a588753b4a9" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.056" + "text/html": [ + "Total execution time: 00:00:00.056" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 9 + "source": [ + "-- Code here:" + ] + } + ], + "metadata": { + "extensions": { + "vscode": { + "version": 1, + "views": [] + } + }, + "kernelspec": { + "display_name": "SQL", + "language": "sql", + "name": "SQL" + }, + "language_info": { + "name": "sql", + "version": "" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 4aa0dfa1a58959efdbdd2ae0efd156975430a47c Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 9 Oct 2025 18:58:18 -0500 Subject: [PATCH 03/22] Update SQL-Part-2-Studio.ipynb --- sql-part-2/studio/SQL-Part-2-Studio.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-part-2/studio/SQL-Part-2-Studio.ipynb b/sql-part-2/studio/SQL-Part-2-Studio.ipynb index 527dbf6d4..3fddb39a8 100644 --- a/sql-part-2/studio/SQL-Part-2-Studio.ipynb +++ b/sql-part-2/studio/SQL-Part-2-Studio.ipynb @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "azdata_cell_guid": "fc1a211d-ea4e-446a-bbf8-e31499c50aba" }, @@ -68,7 +68,7 @@ } ], "source": [ - "-- Code here:" + "The sky\n" ] }, { From 1a53d0da2569a70c4719363a81b98ce373816dd8 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 9 Oct 2025 18:59:59 -0500 Subject: [PATCH 04/22] Update SQL-Part-2-Studio.ipynb --- sql-part-2/studio/SQL-Part-2-Studio.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql-part-2/studio/SQL-Part-2-Studio.ipynb b/sql-part-2/studio/SQL-Part-2-Studio.ipynb index 3fddb39a8..7738ebc20 100644 --- a/sql-part-2/studio/SQL-Part-2-Studio.ipynb +++ b/sql-part-2/studio/SQL-Part-2-Studio.ipynb @@ -68,7 +68,8 @@ } ], "source": [ - "The sky\n" + "The sky\n", + "1859 \n" ] }, { From b2722eb8d504bec68174b0f76b1c3639f6afc54f Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 9 Oct 2025 20:50:33 -0500 Subject: [PATCH 05/22] Most Recent Most Recent --- .gitignore | 1 + sql-part-1/studio/SQL-Part-1-Studio.ipynb | 36 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cee27e267..dc1d47334 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .ipynb_checkpoints venv/ +sql-part-2/studio/SQL Class 1 Studio.sql diff --git a/sql-part-1/studio/SQL-Part-1-Studio.ipynb b/sql-part-1/studio/SQL-Part-1-Studio.ipynb index 7034908a7..73d81f49f 100644 --- a/sql-part-1/studio/SQL-Part-1-Studio.ipynb +++ b/sql-part-1/studio/SQL-Part-1-Studio.ipynb @@ -38,7 +38,11 @@ }, "outputs": [], "source": [ - "-- return top 100 results" + "USE BooksDB \n", + "select TOP 100 book_id,authors,title,average_rating as \"rating\"\n", + "from dbo.books\n", + "order by average_rating desc\n", + "-- The Complete Calvin and Hobbes" ] }, { @@ -58,7 +62,11 @@ }, "outputs": [], "source": [ - "-- return least popular book" + "use BooksDB\n", + "select TOP 1 book_id,authors,title,average_rating\n", + "from dbo.books\n", + "order by average_rating\n", + "-- One Night at the Call Center" ] }, { @@ -78,7 +86,11 @@ }, "outputs": [], "source": [ - "-- return most popular tag" + "use BooksDB\n", + "SELECT TOP 1 tag_id, \"count\"\n", + "FROM BooksDB.dbo.book_tags\n", + "ORDER BY \"count\" DESC\n", + "-- 30574" ] }, { @@ -98,7 +110,11 @@ }, "outputs": [], "source": [ - "-- return name of most popular tag" + "use BooksDB\n", + "SELECT tag_id, tag_name\n", + "FROM BooksDB.dbo.tags\n", + "WHERE tag_id LIKE 30574\n", + "-- to-read" ] }, { @@ -118,7 +134,11 @@ }, "outputs": [], "source": [ - "-- return number of books published in the first decade of 2000" + "--use BooksDB\n", + "select count(*)\n", + "from dbo.books\n", + "where original_publication_year BETWEEN 2000 and 2010\n", + "-- 3594" ] }, { @@ -138,7 +158,11 @@ }, "outputs": [], "source": [ - "-- return number of books that contain the word, \"happy\"" + "use BooksDB\n", + "select count(title)\n", + "from dbo.books\n", + "WHERE title LIKE '%Happy%';\n", + "--13" ] }, { From 48d2453092aa82a55e9d2bfbd882c0cd239f2eb3 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Fri, 10 Oct 2025 15:01:21 -0500 Subject: [PATCH 06/22] Uploadi to Git --- .../exercises/SQL-Part-2-Exercises.ipynb | 306 ++++++++++-------- 1 file changed, 177 insertions(+), 129 deletions(-) diff --git a/sql-part-2/exercises/SQL-Part-2-Exercises.ipynb b/sql-part-2/exercises/SQL-Part-2-Exercises.ipynb index 0ce26bb6e..6ef138920 100644 --- a/sql-part-2/exercises/SQL-Part-2-Exercises.ipynb +++ b/sql-part-2/exercises/SQL-Part-2-Exercises.ipynb @@ -1,20 +1,11 @@ { - "metadata": { - "kernelspec": { - "name": "SQL", - "display_name": "SQL", - "language": "sql" - }, - "language_info": { - "name": "sql", - "version": "" - } - }, - "nbformat_minor": 2, - "nbformat": 4, "cells": [ { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "2b5a5976-8b51-4e24-a08d-234ef97f379a" + }, "source": [ "# Exercises\n", "\n", @@ -23,267 +14,324 @@ "## String Functions\n", "\n", "Write a query that returns the last 3 characters of the base name in other_FHV_services_jan_aug_2015. Do you see anything that is a common abbreviation at the end of business names?" - ], - "metadata": { - "azdata_cell_guid": "2b5a5976-8b51-4e24-a08d-234ef97f379a" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "392f7b72-9acf-44a4-bb53-6c29090c5d75", + "language": "sql", "tags": [], - "language": "sql" + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", - "data": { - "text/html": "Commands completed successfully." - }, - "metadata": {} - }, - { - "output_type": "display_data", - "data": { - "text/html": "Total execution time: 00:00:00" - }, - "metadata": {} + "ename": "", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31mRunning cells with 'Python 3.13.7' requires the ipykernel package.\n", + "\u001b[1;31mCreate a Python Environment with the required packages.\n", + "\u001b[1;31mOr install 'ipykernel' using the command: 'c:/Users/njoha/AppData/Local/Programs/Python/Python313/python.exe -m pip install ipykernel -U --user --force-reinstall'" + ] } ], - "execution_count": 8 + "source": [ + "select RIGHT(Base_Name,3)\n", + "from dbo.other_FHV_services_jan_aug_2015\n" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "The number of trips and the number of pickups are both stored as strings in other_FHV_services_jan_aug_2015. This is because the data provided included spaces in some of the numbers. Write a query that returns the location of spaces in both of these columns." - ], "metadata": { "azdata_cell_guid": "6c206898-77f4-4357-8d17-33192980f45d" }, - "attachments": {} + "source": [ + "The number of trips and the number of pickups are both stored as strings in other_FHV_services_jan_aug_2015. This is because the data provided included spaces in some of the numbers. Write a query that returns the location of spaces in both of these columns." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": 9, "metadata": { "azdata_cell_guid": "3c810c3d-4e66-447b-8326-19e59d8a1b88", - "language": "sql" + "language": "sql", + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 9 + "source": [] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "b138ac53-9fff-4320-9ff1-08717873f2ee" + }, "source": [ "## Date Functions\n", "\n", "For other_FHV_services_jan_aug_2015, display the name of month of the pickup date and order in descending order. Is the result of this query what you expected?" - ], - "metadata": { - "azdata_cell_guid": "b138ac53-9fff-4320-9ff1-08717873f2ee" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "8abd404c-a360-4b10-8d6b-8b34ef763bc7", + "language": "sql", "tags": [], - "language": "sql" + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 10 + "source": [ + "select month(Pick_Up_Date)\n", + "from dbo.other_FHV_services_jan_aug_2015" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "Using other_FHV_services_jan_aug_2015, write a query that returns the day number of the pickup date and month name and orders it in ascending order by day number." - ], "metadata": { "azdata_cell_guid": "aa6bf15c-b847-45f0-ba0d-79c7636c4578" }, - "attachments": {} + "source": [ + "Using other_FHV_services_jan_aug_2015, write a query that returns the day number of the pickup date and month name and orders it in ascending order by day number." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "46dcd617-8dcf-4c15-b5fa-c0ec04f2bf29", - "language": "sql" + "language": "sql", + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 11 + "source": [ + "select DATEPART(month, Pick_Up_Date) as MonthPart, DATEPART(day, Pick_Up_Date) as DayPart\n", + "from dbo.other_FHV_services_jan_aug_2015\n", + "ORDER BY DayPart asc" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "348342a2-6039-43b1-8461-841288deee94" + }, "source": [ "## Aggregate Functions\n", "\n", "Write a query that returns the most easterly Lyft pickup." - ], - "metadata": { - "azdata_cell_guid": "348342a2-6039-43b1-8461-841288deee94" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "f2cb1b41-c92a-47ea-bd77-7bafd78af1d4", + "language": "sql", "tags": [], - "language": "sql" + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 12 + "source": [ + "select max(start_lng)\n", + "from dbo.lyft\n", + "---73.72315" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "Write a query the returns the most northerly Lyft pickup." - ], "metadata": { "azdata_cell_guid": "bd589862-044d-4909-8565-8aa4771d9c00" }, - "attachments": {} + "source": [ + "Write a query the returns the most northerly Lyft pickup." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "189b7c25-0dfa-4ca0-a683-d402b3875abd", - "language": "sql" + "language": "sql", + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 13 + "source": [ + "select max(start_lat)\n", + "from dbo.lyft\n", + "--40.93562" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "Using other_FHV_services_jan_aug_2015, write a query that connects the the base number and the base name in a string that uses the following format: base_number: base_name." - ], "metadata": { "azdata_cell_guid": "674f8758-14bf-4712-b029-0ad0447617fb" }, - "attachments": {} + "source": [ + "Using other_FHV_services_jan_aug_2015, write a query that connects the the base number and the base name in a string that uses the following format: base_number: base_name." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "f6f4b247-63c0-4997-8769-204e37a55c08", - "language": "sql" + "language": "sql", + "vscode": { + "languageId": "sql" + } }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 14 + "source": [ + "select CONCAT(Base_Number, ' - ', Base_Name)\n", + "from dbo.other_FHV_services_jan_aug_2015" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.13.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 56f2ec804c9b982e54aa36575bbe56ecf37f7a6c Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 14 Oct 2025 20:16:41 -0500 Subject: [PATCH 07/22] 4 4 --- sql-part-2/studio/SQL Class 1 Studio.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sql-part-2/studio/SQL Class 1 Studio.sql diff --git a/sql-part-2/studio/SQL Class 1 Studio.sql b/sql-part-2/studio/SQL Class 1 Studio.sql new file mode 100644 index 000000000..024c02c4f --- /dev/null +++ b/sql-part-2/studio/SQL Class 1 Studio.sql @@ -0,0 +1,4 @@ +USE BooksDB +select TOP 100 book_id,authors,title,average_rating as "rating" +from dbo.books +order by average_rating desc \ No newline at end of file From c866f3a8886e9c062603db015fdef537ab16fc2e Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 14 Oct 2025 20:19:45 -0500 Subject: [PATCH 08/22] Upload 2025.10.14 --- sql-part-2/studio/SQL-Part-2-Studio.ipynb | 39 ++++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/sql-part-2/studio/SQL-Part-2-Studio.ipynb b/sql-part-2/studio/SQL-Part-2-Studio.ipynb index 7738ebc20..a1772f47e 100644 --- a/sql-part-2/studio/SQL-Part-2-Studio.ipynb +++ b/sql-part-2/studio/SQL-Part-2-Studio.ipynb @@ -68,8 +68,10 @@ } ], "source": [ - "The sky\n", - "1859 \n" + "select top 1 len(title) as title_length, title\n", + "from BooksDB.dbo.books\n", + "ORDER BY title_length desc\n", + "--186 characters: Soccernomics: Why England Loses, Why Germany and Brazil Win, and Why the U.S., Japan, Australia, Turkey--and Even Iraq--Are Destined to Become the Kings of the World's Most Popular Sport\n" ] }, { @@ -88,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "azdata_cell_guid": "61423c75-cb55-470f-b062-a1901d3da67c" }, @@ -113,7 +115,11 @@ } ], "source": [ - "-- Code here:" + "select top 1 MIN(len(authors)) as author_length,authors, title\n", + "from BooksDB.dbo.books\n", + "GROUP BY authors,title\n", + "ORDER BY author_length asc\n", + "--Avi/ 3 characters" ] }, { @@ -132,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "azdata_cell_guid": "f58433db-eb3b-46e0-bb4d-85ca52d359b5" }, @@ -157,7 +163,10 @@ } ], "source": [ - "-- Code here:" + "select title\n", + "from BooksDB.dbo.books\n", + "where title LIKE '%the%'\n", + "--4702 ROWS" ] }, { @@ -172,7 +181,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "azdata_cell_guid": "850f04c8-458a-4cfb-95c4-4dbb7a3d63d0" }, @@ -197,7 +206,10 @@ } ], "source": [ - "-- Code here:" + "select left(authors,1) as begin_author_name\n", + "from BooksDB.dbo.books\n", + "where left (authors,1) = 'z' \n", + "-- 11 authors" ] }, { @@ -214,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "azdata_cell_guid": "5a85f5ae-dd59-4fa1-828a-c63fa330ff7f" }, @@ -239,7 +251,9 @@ } ], "source": [ - "-- Code here:" + "select count(title) as 'CountNotInEN)\n", + "from BooksDB.dbo.books\n", + "where language_code != 'en'" ] }, { @@ -296,7 +310,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "azdata_cell_guid": "26705af1-6191-48b9-b649-7bc93cad102d" }, @@ -321,7 +335,8 @@ } ], "source": [ - "-- Code here:" + "select CONCAT(title, ' by ', authors,' in ',language_code,' language.')\n", + "from BooksDB.dbo.books\n" ] }, { From 386bcddfef02c8b2e09048f9a52383404d6b7624 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 14 Oct 2025 20:25:43 -0500 Subject: [PATCH 09/22] Uploading SQL-Part-2-Studio.ipynb --- sql-part-2/studio/SQL-Part-2-Studio.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql-part-2/studio/SQL-Part-2-Studio.ipynb b/sql-part-2/studio/SQL-Part-2-Studio.ipynb index a1772f47e..9c1ce2828 100644 --- a/sql-part-2/studio/SQL-Part-2-Studio.ipynb +++ b/sql-part-2/studio/SQL-Part-2-Studio.ipynb @@ -71,7 +71,8 @@ "select top 1 len(title) as title_length, title\n", "from BooksDB.dbo.books\n", "ORDER BY title_length desc\n", - "--186 characters: Soccernomics: Why England Loses, Why Germany and Brazil Win, and Why the U.S., Japan, Australia, Turkey--and Even Iraq--Are Destined to Become the Kings of the World's Most Popular Sport\n" + "--186 characters: Soccernomics: Why England Loses, Why Germany and Brazil Win, and Why the U.S., Japan, Australia, Turkey--and Even Iraq--Are Destined to Become the Kings of the World's Most Popular Sport\n", + "--THEN" ] }, { From 28c3801d0a801549d5a965b97c71e7d0a934ae30 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 14 Oct 2025 20:29:34 -0500 Subject: [PATCH 10/22] CCommit --- sql-part-2/studio/SQL-Part-2-Studio.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-part-2/studio/SQL-Part-2-Studio.ipynb b/sql-part-2/studio/SQL-Part-2-Studio.ipynb index 9c1ce2828..1ffd66972 100644 --- a/sql-part-2/studio/SQL-Part-2-Studio.ipynb +++ b/sql-part-2/studio/SQL-Part-2-Studio.ipynb @@ -72,7 +72,7 @@ "from BooksDB.dbo.books\n", "ORDER BY title_length desc\n", "--186 characters: Soccernomics: Why England Loses, Why Germany and Brazil Win, and Why the U.S., Japan, Australia, Turkey--and Even Iraq--Are Destined to Become the Kings of the World's Most Popular Sport\n", - "--THEN" + "--THE LONGEST TITLE" ] }, { From 7cb7c01edff5f2ba4fedea22f2248a8d4aeeec3b Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 16 Oct 2025 15:39:21 -0500 Subject: [PATCH 11/22] 10.16.2025 From 4c7264031bd99f3feca88afa79231fef978f755b Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 16 Oct 2025 15:47:41 -0500 Subject: [PATCH 12/22] Update SQL-Part-3-Studio.ipynb --- sql-part-3/studio/SQL-Part-3-Studio.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-part-3/studio/SQL-Part-3-Studio.ipynb b/sql-part-3/studio/SQL-Part-3-Studio.ipynb index eea5af39a..4aa6d86a8 100644 --- a/sql-part-3/studio/SQL-Part-3-Studio.ipynb +++ b/sql-part-3/studio/SQL-Part-3-Studio.ipynb @@ -50,7 +50,7 @@ }, "outputs": [], "source": [ - "-- Solution" + "-- Solution The sky is blue" ] }, { From 032b3894c95fae1fa08b5d32e9da42ead203ba5f Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 16 Oct 2025 15:49:53 -0500 Subject: [PATCH 13/22] 15.50 --- sql-part-3/studio/SQL-Part-3-Studio.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-part-3/studio/SQL-Part-3-Studio.ipynb b/sql-part-3/studio/SQL-Part-3-Studio.ipynb index 4aa6d86a8..490c044b8 100644 --- a/sql-part-3/studio/SQL-Part-3-Studio.ipynb +++ b/sql-part-3/studio/SQL-Part-3-Studio.ipynb @@ -50,7 +50,7 @@ }, "outputs": [], "source": [ - "-- Solution The sky is blue" + "-- Solution The sky is blue 15.50" ] }, { From a48c553ae958c659f4a6bfc011b0209fbc0999d0 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 16 Oct 2025 15:52:14 -0500 Subject: [PATCH 14/22] 15.52 --- .../exercises/SQL-Part-3-Exercises.ipynb | 222 ++++++++---------- 1 file changed, 99 insertions(+), 123 deletions(-) diff --git a/sql-part-3/exercises/SQL-Part-3-Exercises.ipynb b/sql-part-3/exercises/SQL-Part-3-Exercises.ipynb index 3b63aec8a..e264a6cc6 100644 --- a/sql-part-3/exercises/SQL-Part-3-Exercises.ipynb +++ b/sql-part-3/exercises/SQL-Part-3-Exercises.ipynb @@ -1,20 +1,10 @@ { - "metadata": { - "kernelspec": { - "name": "SQL", - "display_name": "SQL", - "language": "sql" - }, - "language_info": { - "name": "sql", - "version": "" - } - }, - "nbformat_minor": 2, - "nbformat": 4, "cells": [ { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "c739e118-2a3a-45f9-bd51-090c836e7a7e" + }, "source": [ "# SQL Part 3 Exercises: Joins\n", "\n", @@ -27,13 +17,13 @@ "In **questions 5-8**, you will be asked to join tables to find results about titles, tags, and the books users want to read.\n", "\n", "As you go through the questions, you will see 'Minimum Desired Output'. This will provide you with the bare minimum columns needed to answer the questions. When you write the queries, add as many additional columns as you need to best find your answers." - ], - "metadata": { - "azdata_cell_guid": "c739e118-2a3a-45f9-bd51-090c836e7a7e" - } + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "cdfaf133-068f-496d-8ecb-ecfde5c8d9f5" + }, "source": [ "## QUESTION 1: Exploring a `LEFT JOIN` using the `books` and `to_read` tables\n", "\n", @@ -41,19 +31,22 @@ "\n", "**Part A:** Look at Query 1, which table is the 'Left' table and which is the 'Right'?\n", "\n", - "> Your Answer:\n", + "> Your Answer: Best_book_ID is the left and TR.BOOK_ID is the right\n", "\n", "**Part B:** Using table 2, answer the following questions: \n", "- When we added a `WHERE tr.user_id IS NOT NULL` clause (line 14), how did the table change? Why?\n", "\n", - "> Your Answer:" - ], - "metadata": { - "azdata_cell_guid": "cdfaf133-068f-496d-8ecb-ecfde5c8d9f5" - } + "> Your Answer: " + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "azdata_cell_guid": "a2038d22-5f42-4539-af89-d1fd36c66d47", + "language": "sql" + }, + "outputs": [], "source": [ "/*\n", "-- Query 1: LEFT JOIN\n", @@ -71,19 +64,13 @@ "WHERE tr.user_id IS NOT NULL\n", "ORDER BY b.average_rating;\n", "*/" - ], - "metadata": { - "vscode": { - "languageId": "sql" - }, - "azdata_cell_guid": "a2038d22-5f42-4539-af89-d1fd36c66d47", - "language": "sql" - }, - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "e5b293e1-3c99-4696-93db-71e77df50757" + }, "source": [ "## **QUESTION 2:** Exploring `RIGHT` joins with the `books` and `to_read` tables\n", "\n", @@ -91,18 +78,21 @@ "\n", "**Part A:** Looking at the query, which table is the 'Left' and which is the 'Right'?\n", "\n", - "> Your Answer:\n", + "> Your Answer: b.best_book_id is left, Tr.book_id is right\n", "\n", "**Part B:** How do the RIGHT-joined tables differ from the LEFT-joined tables in Question 1?\n", "\n", - "> Your Answer:" - ], - "metadata": { - "azdata_cell_guid": "e5b293e1-3c99-4696-93db-71e77df50757" - } + "> Your Answer: results are all results in the right table and and any mathcing records in the left." + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "azdata_cell_guid": "3916ff86-e45b-47d3-ae94-c1ee7903c7b9", + "language": "sql" + }, + "outputs": [], "source": [ "/*\n", "-- Query 1: RIGHT JOIN\n", @@ -111,19 +101,13 @@ "RIGHT JOIN BooksDB.dbo.to_read AS tr\n", "ON b.best_book_id = tr.book_id;\n", "*/" - ], - "metadata": { - "vscode": { - "languageId": "sql" - }, - "azdata_cell_guid": "3916ff86-e45b-47d3-ae94-c1ee7903c7b9", - "language": "sql" - }, - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "db92a0de-8cbe-47b2-a989-c77138c427fd" + }, "source": [ "## **QUESTION 3:** Exploring FULL JOINS with the `books` and `to_read` tables\n", "\n", @@ -132,13 +116,16 @@ "**Part A:** Look at the table and explore how it was populated. Try manipulating the query to better understand how this table works. Try adding a WHERE clause, or ORDER BY a column on the `books` table. Based on your exploration, can you think of when you might want a FULL join rather than a LEFT, RIGHT, or INNER?\n", "\n", "> Your Answer:" - ], - "metadata": { - "azdata_cell_guid": "db92a0de-8cbe-47b2-a989-c77138c427fd" - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "azdata_cell_guid": "421beb17-491d-4d0b-9a83-4383e9a878f6", + "language": "sql" + }, + "outputs": [], "source": [ "/*\n", "-- FULL JOIN\n", @@ -147,19 +134,13 @@ "FULL JOIN BooksDB.dbo.to_read AS tr\n", "ON b.book_id = tr.book_id;\n", "*/" - ], - "metadata": { - "vscode": { - "languageId": "sql" - }, - "azdata_cell_guid": "421beb17-491d-4d0b-9a83-4383e9a878f6", - "language": "sql" - }, - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "c9219b58-ba70-4f18-b40d-5a959f50ec10" + }, "source": [ "## **QUESTION 4:** Exploring INNER Joins with the `books` and `to_read` tables\n", "\n", @@ -176,13 +157,16 @@ "**Part C:** When using SQL, you are usually returning much larger tables so every line of code will add to the compilation and return time. Rewrite this inner join query so that it contains no redundant code.\n", "\n", "> Your Answer: Update the query in the code box below." - ], - "metadata": { - "azdata_cell_guid": "c9219b58-ba70-4f18-b40d-5a959f50ec10" - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "azdata_cell_guid": "6ee6b18f-d81b-46b8-857b-95e2e88bd1fd", + "language": "sql" + }, + "outputs": [], "source": [ "/*\n", "-- INNER JOIN\n", @@ -193,19 +177,13 @@ "WHERE b.title IS NOT NULL\n", "ORDER BY tr.book_id;\n", "*/" - ], - "metadata": { - "vscode": { - "languageId": "sql" - }, - "azdata_cell_guid": "6ee6b18f-d81b-46b8-857b-95e2e88bd1fd", - "language": "sql" - }, - "outputs": [], - "execution_count": null + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "6c20039d-2496-42c6-b5fc-db8f1ded0ce4" + }, "source": [ "## **QUESTION 5:** Using joins to find the most tagged book and the most popular tag\n", "\n", @@ -234,28 +212,25 @@ "*Minimum Desired Output:* The tag name for the most popular tag used for the most tagged book.\n", "\n", "**Tag Name:**" - ], - "metadata": { - "azdata_cell_guid": "6c20039d-2496-42c6-b5fc-db8f1ded0ce4" - } + ] }, { "cell_type": "code", - "source": [ - "-- Code Here" - ], + "execution_count": null, "metadata": { - "vscode": { - "languageId": "sql" - }, "azdata_cell_guid": "c1d7f859-cf56-424e-bd90-0203ab5a1cdd", "language": "sql" }, "outputs": [], - "execution_count": null + "source": [ + "-- Code Here" + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "0afe0108-c632-4cde-b7e0-5e699c066e03" + }, "source": [ "## QUESTION 6: Find a book based on a tag of your choice using joins.\n", "\n", @@ -276,28 +251,25 @@ "*Minimum Desired Output:* title and tag count\n", "\n", "**Your Title and Number of times the tag was used:**" - ], - "metadata": { - "azdata_cell_guid": "0afe0108-c632-4cde-b7e0-5e699c066e03" - } + ] }, { "cell_type": "code", - "source": [ - "-- Code Here:" - ], + "execution_count": null, "metadata": { - "vscode": { - "languageId": "sql" - }, "azdata_cell_guid": "761b4d46-2218-486e-8336-cda901bc8551", "language": "sql" }, "outputs": [], - "execution_count": null + "source": [ + "-- Code Here:" + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "d684cef6-783d-43d1-a017-f5e5d83c46da" + }, "source": [ "## **QUESTION 7:** What are the top 10 most popular book titles on the 'to read' list?\n", "\n", @@ -310,28 +282,25 @@ "*Hint:* Suggest using an alias for the aggregation you will need to run on the `user_id`\n", "\n", "*Minimum Desired Output:* title and aliased column" - ], - "metadata": { - "azdata_cell_guid": "d684cef6-783d-43d1-a017-f5e5d83c46da" - } + ] }, { "cell_type": "code", - "source": [ - "-- Code Here:" - ], + "execution_count": null, "metadata": { - "vscode": { - "languageId": "sql" - }, "azdata_cell_guid": "3247ef18-3603-47b0-b2a1-0b6a70e8de33", "language": "sql" }, "outputs": [], - "execution_count": null + "source": [ + "-- Code Here:" + ] }, { "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "d7f2f6a3-ecc3-4629-aacd-312723da07af" + }, "source": [ "## **QUESTION 8:** Largest 'To Read' Lists\n", "\n", @@ -342,25 +311,32 @@ "_Minimum Desired Output:_ `user_id` and your aliased column of titles.\n", "\n", "**Part B:** The longest list length is 15 titles total, and is shared by 4 different users. Select one of the uses and print out their entire 'to read' list." - ], - "metadata": { - "azdata_cell_guid": "d7f2f6a3-ecc3-4629-aacd-312723da07af" - } + ] }, { "cell_type": "code", - "source": [ - "-- Code Here:" - ], + "execution_count": null, "metadata": { - "vscode": { - "languageId": "sql" - }, "azdata_cell_guid": "a7ae1df0-4d43-4e27-b635-eed926d2311f", "language": "sql" }, "outputs": [], - "execution_count": null + "source": [ + "-- Code Here:" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "kernelspec": { + "display_name": "SQL", + "language": "sql", + "name": "SQL" + }, + "language_info": { + "name": "sql", + "version": "" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From dde1fca61c72000a99e7dbd486f16f075d42c459 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 16 Oct 2025 20:12:20 -0500 Subject: [PATCH 15/22] Update SQL-Part-3-Studio.ipynb --- sql-part-3/studio/SQL-Part-3-Studio.ipynb | 28 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/sql-part-3/studio/SQL-Part-3-Studio.ipynb b/sql-part-3/studio/SQL-Part-3-Studio.ipynb index 490c044b8..9eb964ee5 100644 --- a/sql-part-3/studio/SQL-Part-3-Studio.ipynb +++ b/sql-part-3/studio/SQL-Part-3-Studio.ipynb @@ -50,7 +50,14 @@ }, "outputs": [], "source": [ - "-- Solution The sky is blue 15.50" + "SELECT bt.tag_id, COUNT(bt.tag_id) AS tag_count, t.tag_name\n", + "FROM BooksDB.dbo.book_tags AS bt\n", + "Inner JOIN BooksDB.dbo.tags AS t\n", + "ON t.tag_id = t.tag_id\n", + "WHERE t.tag_name LIKE '%woman%' OR t.tag_name LIKE '%female%'\n", + "GROUP BY bt.tag_id, t.tag_name\n", + "HAVING COUNT(bt.[count]) > 1000\n", + "ORDER BY tag_count DESC;" ] }, { @@ -112,7 +119,13 @@ }, "outputs": [], "source": [ - "-- Event 1 Query" + "SELECT bt.tag_id, COUNT(bt.tag_id) AS tag_count, t.tag_name\n", + "FROM BooksDB.dbo.book_tags AS bt\n", + "Inner JOIN BooksDB.dbo.tags AS t\n", + "ON t.tag_id = t.tag_id\n", + "WHERE t.tag_name LIKE '%Witch%' OR t.tag_name LIKE '%Black-Cat%'\n", + "GROUP BY bt.tag_id, t.tag_name\n", + "ORDER BY tag_count DESC;" ] }, { @@ -121,7 +134,7 @@ "source": [ "### Summarize Event 1\n", "\n", - "Double-click to edit." + "Halloween,Disable Employment Month" ] }, { @@ -134,7 +147,14 @@ }, "outputs": [], "source": [ - "-- Event 2 Query" + "SELECT bt.tag_id, COUNT(bt.tag_id) AS tag_count, t.tag_name\n", + "FROM BooksDB.dbo.book_tags AS bt\n", + "Inner JOIN BooksDB.dbo.tags AS t\n", + "ON t.tag_id = t.tag_id\n", + "WHERE t.tag_name LIKE '%employment%' OR t.tag_name LIKE '%disability%'\n", + "GROUP BY bt.tag_id, t.tag_name\n", + "HAVING COUNT(bt.[count]) < 1000\n", + "oRDER BY tag_count DESC;" ] }, { From c78e2422f36b4ae211192455cd939660408170d9 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Sat, 18 Oct 2025 15:57:17 -0500 Subject: [PATCH 16/22] 10/18/2025 14:22:10 -0700 --- .../exercises/SQL-Part-4-Exercises.ipynb | 186 ++++++++++-------- 1 file changed, 100 insertions(+), 86 deletions(-) diff --git a/sql-part-4/exercises/SQL-Part-4-Exercises.ipynb b/sql-part-4/exercises/SQL-Part-4-Exercises.ipynb index 5e3c18ec6..8ae2bb593 100644 --- a/sql-part-4/exercises/SQL-Part-4-Exercises.ipynb +++ b/sql-part-4/exercises/SQL-Part-4-Exercises.ipynb @@ -1,203 +1,217 @@ { - "metadata": { - "kernelspec": { - "name": "SQL", - "display_name": "SQL", - "language": "sql" - }, - "language_info": { - "name": "sql", - "version": "" - } - }, - "nbformat_minor": 2, - "nbformat": 4, "cells": [ { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "10006a10-882f-4f55-8d42-f36044fdb6c7" + }, "source": [ "# Exercises: Complex queries\n", "\n", "For the exercises, you are tasked with writing five queries that will help you delve deeper into BooksDB. You can choose whether you want to use a correlated subquery, a nested subquery, the UNION operator, the INTERSECT operator, or the EXCEPT operator for each one. You may not use joins or add multiple statements to the WHERE clause.\n", "\n", "1. Write a query that will return the number of users who rated a book above it's average rating." - ], - "metadata": { - "azdata_cell_guid": "10006a10-882f-4f55-8d42-f36044fdb6c7" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": 1, "metadata": { "azdata_cell_guid": "203eb95e-6585-435f-8a8e-bfa0dfe6f7c0", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 1 + "source": [] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "2. Write a query that returns the book ids of all books that have over 1000 ratings of 1 star or over 1000 ratings of 5 stars." - ], "metadata": { "azdata_cell_guid": "7f849931-6c9c-4cd9-b3ba-66871052673d" }, - "attachments": {} + "source": [ + "2. Write a query that returns the book ids of all books that have over 1000 ratings of 1 star or over 1000 ratings of 5 stars." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": 2, "metadata": { "azdata_cell_guid": "bce732e3-1590-457b-b1f9-5319345ff790" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 2 + "source": [] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "3. Write a query that returns the book ids of all books that have over 1000 ratings of 1 star and over 1000 ratings of 5 stars." - ], "metadata": { "azdata_cell_guid": "9c53b866-c8e8-465e-b089-7702b191a15e" }, - "attachments": {} + "source": [ + "3. Write a query that returns the book ids of all books that have over 1000 ratings of 1 star and over 1000 ratings of 5 stars." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": 3, "metadata": { "azdata_cell_guid": "43e39973-5a29-45ff-b2a9-9c658a19c296" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 3 + "source": [] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "4. Write a query that returns the book ids of books that have a language code of \"en-US\" and not a langugae code of \"en-GB\"." - ], "metadata": { "azdata_cell_guid": "2bd4844b-83af-490f-97cd-fdc1fa2944ec" }, - "attachments": {} + "source": [ + "4. Write a query that returns the book ids of books that have a language code of \"en-US\" and not a langugae code of \"en-GB\"." + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "ba5a1b61-19c0-4d70-ae8d-2daae6ae1e21" }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 4 + "source": [ + "select * \n", + "from booksdb.dbo.books\n", + "where language_code = 'en-us'" + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "5. Write a query that returns the names of the tags and the tag ids for tags that were used over 100,000 times for a book. " - ], "metadata": { "azdata_cell_guid": "6ddd588f-a84c-4c77-93ac-e8c8bd21d0f5" }, - "attachments": {} + "source": [ + "5. Write a query that returns the names of the tags and the tag ids for tags that were used over 100,000 times for a book. " + ] }, { "cell_type": "code", - "source": [ - "" - ], + "execution_count": 5, "metadata": { "azdata_cell_guid": "90f61ad7-65cb-4ea8-85a3-d8c815cfe347", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00" + "text/html": [ + "Total execution time: 00:00:00" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 5 + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SQL", + "language": "sql", + "name": "SQL" + }, + "language_info": { + "name": "sql", + "version": "" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 03254e82aaa8ce23a6009b510e3ff752fa5a09c0 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 21 Oct 2025 20:06:25 -0500 Subject: [PATCH 17/22] 10212025 2006 --- sql-part-4/studio/SQL-Part-4-Studio.ipynb | 203 +++++++++++++--------- 1 file changed, 117 insertions(+), 86 deletions(-) diff --git a/sql-part-4/studio/SQL-Part-4-Studio.ipynb b/sql-part-4/studio/SQL-Part-4-Studio.ipynb index 1a394fcbd..b0dde8304 100644 --- a/sql-part-4/studio/SQL-Part-4-Studio.ipynb +++ b/sql-part-4/studio/SQL-Part-4-Studio.ipynb @@ -1,157 +1,169 @@ { - "metadata": { - "kernelspec": { - "name": "SQL", - "display_name": "SQL", - "language": "sql" - }, - "language_info": { - "name": "sql", - "version": "" - }, - "extensions": { - "vscode": { - "version": 1, - "views": [] - } - } - }, - "nbformat_minor": 2, - "nbformat": 4, "cells": [ { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "3ea3f8a2-b444-4354-be8b-eebc139b3c13" + }, "source": [ "# SQL Part 4 Studio\n", "\n", "For this studio, you will be working in small groups and using the BooksDB.  One group member should screen share while fellow group members code along in their own notebooks.  Each group member will submit a link to their studio notebook.\n", "\n", "You are back at the bookstore helping employees with their inventory of books.   Four employees need your help with finding books to create in-store displays.  Read their requests and decide if you want to use a correlated subquery, nested subquery, UNION operator, EXCEPT operator, or INTERSECT operator.  You may not use any joins or add multiple statements to the WHERE clause unless explicitly asked." - ], - "metadata": { - "azdata_cell_guid": "3ea3f8a2-b444-4354-be8b-eebc139b3c13" - }, - "attachments": {} + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "5c8b1c77-0878-4dc6-8e79-7f64e5e1df0d" + }, "source": [ "## QUESTION 1:  Willow\n", "\n", "Willow wants a list of book titles that have multiple authors attributed to them.  Write a query to return her desired results." - ], - "metadata": { - "azdata_cell_guid": "5c8b1c77-0878-4dc6-8e79-7f64e5e1df0d" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "46c76d2f-acbc-4fd2-9c2a-367044fda616", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.080" + "text/html": [ + "Total execution time: 00:00:00.080" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 1 + "source": [ + "SELECT title, authors\n", + "FROM BooksDB.dbo.books AS b\n", + "WHERE (\n", + " SELECT COUNT(*)\n", + " FROM BooksDB.dbo.books AS b2\n", + " WHERE b2.title = b.title\n", + ") > 1\n", + "ORDER BY title, authors;" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "06f2a08a-a54e-484e-8053-c74594da9db2" + }, "source": [ "## QUESTION 2: Ira\n", "\n", "Ira was asked by a customer for titles that have been tagged \"Meditation\".  As you create a query for Ira, think about how the tables in BooksDB are organized as you write your query." - ], - "metadata": { - "azdata_cell_guid": "06f2a08a-a54e-484e-8053-c74594da9db2" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "552924f9-a1cc-4979-8f53-15ba959550c2", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.049" + "text/html": [ + "Total execution time: 00:00:00.049" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 2 + "source": [ + "SELECT title\n", + "FROM BooksDB.dbo.books\n", + "WHERE book_id IN (\n", + " SELECT book_id\n", + " FROM BooksDB.dbo.book_tags\n", + " WHERE tag_id IN (\n", + " SELECT tag_id\n", + " FROM BooksDB.dbo.tags\n", + " WHERE tag_name = 'Meditation'\n", + " )\n", + ");" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "1d758d74-b4f0-4836-bdfe-d7280b5b4592" + }, "source": [ "## QUESTION 3:  Alyce\n", "\n", "Alyce wants to create a display of books with an average rating of 4.2 or higher, but she only wants books that share both title and original title.  Write a query that displays both the original title and title for Alyce, in descending order by rating.  Make sure that none of the original titles contain NULL values either." - ], - "metadata": { - "azdata_cell_guid": "1d758d74-b4f0-4836-bdfe-d7280b5b4592" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": null, "metadata": { "azdata_cell_guid": "2c693b4e-6987-4c49-ba55-61094e677608", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.048" + "text/html": [ + "Total execution time: 00:00:00.048" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 3 + "source": [] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "c3cb4fa8-802c-4130-8740-2adf20ec6a15" + }, "source": [ "## QUESTION 4:  Thisbe\n", "\n", @@ -160,38 +172,57 @@ "**Part A:**   Write a query that compares the publication time with average reader ratings.\n", "\n", "**Part B:**  She wants the list ordered by year, then the book title" - ], - "metadata": { - "azdata_cell_guid": "c3cb4fa8-802c-4130-8740-2adf20ec6a15" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 4, "metadata": { "azdata_cell_guid": "164e0a22-349f-45ed-afe8-0753d5a8c6fc", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.051" + "text/html": [ + "Total execution time: 00:00:00.051" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 4 + "source": [ + "-- Code here:" + ] + } + ], + "metadata": { + "extensions": { + "vscode": { + "version": 1, + "views": [] + } + }, + "kernelspec": { + "display_name": "SQL", + "language": "sql", + "name": "SQL" + }, + "language_info": { + "name": "sql", + "version": "" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 5b91683993b5178c10cb2a59f14b90c9c17832a5 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 21 Oct 2025 20:06:54 -0500 Subject: [PATCH 18/22] 10212025 2006 --- sql-part-4/studio/SQL-Part-4-Studio.ipynb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sql-part-4/studio/SQL-Part-4-Studio.ipynb b/sql-part-4/studio/SQL-Part-4-Studio.ipynb index b0dde8304..33d245509 100644 --- a/sql-part-4/studio/SQL-Part-4-Studio.ipynb +++ b/sql-part-4/studio/SQL-Part-4-Studio.ipynb @@ -156,7 +156,21 @@ "output_type": "display_data" } ], - "source": [] + "source": [ + "WITH matched_books AS (\n", + " SELECT title, average_rating\n", + " FROM booksdb.dbo.books\n", + " WHERE average_rating > 4.2\n", + " AND title IN (\n", + " SELECT original_title\n", + " FROM booksdb.dbo.books\n", + " WHERE average_rating > 4.2\n", + " )\n", + ")\n", + "SELECT title\n", + "FROM matched_books\n", + "ORDER BY average_rating;" + ] }, { "attachments": {}, From 5d4ecbd56d3fc4813e59b9f221a9f5d5795b0ff7 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 21 Oct 2025 20:08:26 -0500 Subject: [PATCH 19/22] 10212025 2008 --- sql-part-4/studio/SQL-Part-4-Studio.ipynb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sql-part-4/studio/SQL-Part-4-Studio.ipynb b/sql-part-4/studio/SQL-Part-4-Studio.ipynb index 33d245509..e03c5423d 100644 --- a/sql-part-4/studio/SQL-Part-4-Studio.ipynb +++ b/sql-part-4/studio/SQL-Part-4-Studio.ipynb @@ -190,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "azdata_cell_guid": "164e0a22-349f-45ed-afe8-0753d5a8c6fc", "tags": [] @@ -216,7 +216,21 @@ } ], "source": [ - "-- Code here:" + "SELECT title,\n", + " original_publication_year,\n", + " average_rating AS book_avg_rating,\n", + " (\n", + " SELECT AVG(rating)\n", + " FROM BooksDB.dbo.ratings AS r\n", + " WHERE r.book_id = b.book_id\n", + " ) AS reader_avg_rating\n", + "FROM BooksDB.dbo.books AS b\n", + "WHERE average_rating < (\n", + " SELECT AVG(rating)\n", + " FROM BooksDB.dbo.ratings AS r\n", + " WHERE r.book_id = b.book_id\n", + ")\n", + "ORDER BY original_publication_year, tit" ] } ], From cc20120481228a38c3e42b27eab19dc5fe1f4929 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Tue, 21 Oct 2025 20:08:54 -0500 Subject: [PATCH 20/22] Update SQL-Part-4-Studio.ipynb --- sql-part-4/studio/SQL-Part-4-Studio.ipynb | 188 ++++++++++++---------- 1 file changed, 102 insertions(+), 86 deletions(-) diff --git a/sql-part-4/studio/SQL-Part-4-Studio.ipynb b/sql-part-4/studio/SQL-Part-4-Studio.ipynb index 1a394fcbd..add42f30a 100644 --- a/sql-part-4/studio/SQL-Part-4-Studio.ipynb +++ b/sql-part-4/studio/SQL-Part-4-Studio.ipynb @@ -1,157 +1,154 @@ { - "metadata": { - "kernelspec": { - "name": "SQL", - "display_name": "SQL", - "language": "sql" - }, - "language_info": { - "name": "sql", - "version": "" - }, - "extensions": { - "vscode": { - "version": 1, - "views": [] - } - } - }, - "nbformat_minor": 2, - "nbformat": 4, "cells": [ { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "3ea3f8a2-b444-4354-be8b-eebc139b3c13" + }, "source": [ "# SQL Part 4 Studio\n", "\n", "For this studio, you will be working in small groups and using the BooksDB.  One group member should screen share while fellow group members code along in their own notebooks.  Each group member will submit a link to their studio notebook.\n", "\n", "You are back at the bookstore helping employees with their inventory of books.   Four employees need your help with finding books to create in-store displays.  Read their requests and decide if you want to use a correlated subquery, nested subquery, UNION operator, EXCEPT operator, or INTERSECT operator.  You may not use any joins or add multiple statements to the WHERE clause unless explicitly asked." - ], - "metadata": { - "azdata_cell_guid": "3ea3f8a2-b444-4354-be8b-eebc139b3c13" - }, - "attachments": {} + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "5c8b1c77-0878-4dc6-8e79-7f64e5e1df0d" + }, "source": [ "## QUESTION 1:  Willow\n", "\n", "Willow wants a list of book titles that have multiple authors attributed to them.  Write a query to return her desired results." - ], - "metadata": { - "azdata_cell_guid": "5c8b1c77-0878-4dc6-8e79-7f64e5e1df0d" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 1, "metadata": { "azdata_cell_guid": "46c76d2f-acbc-4fd2-9c2a-367044fda616", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.080" + "text/html": [ + "Total execution time: 00:00:00.080" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 1 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "06f2a08a-a54e-484e-8053-c74594da9db2" + }, "source": [ "## QUESTION 2: Ira\n", "\n", "Ira was asked by a customer for titles that have been tagged \"Meditation\".  As you create a query for Ira, think about how the tables in BooksDB are organized as you write your query." - ], - "metadata": { - "azdata_cell_guid": "06f2a08a-a54e-484e-8053-c74594da9db2" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 2, "metadata": { "azdata_cell_guid": "552924f9-a1cc-4979-8f53-15ba959550c2", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.049" + "text/html": [ + "Total execution time: 00:00:00.049" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 2 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "1d758d74-b4f0-4836-bdfe-d7280b5b4592" + }, "source": [ "## QUESTION 3:  Alyce\n", "\n", "Alyce wants to create a display of books with an average rating of 4.2 or higher, but she only wants books that share both title and original title.  Write a query that displays both the original title and title for Alyce, in descending order by rating.  Make sure that none of the original titles contain NULL values either." - ], - "metadata": { - "azdata_cell_guid": "1d758d74-b4f0-4836-bdfe-d7280b5b4592" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 3, "metadata": { "azdata_cell_guid": "2c693b4e-6987-4c49-ba55-61094e677608", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.048" + "text/html": [ + "Total execution time: 00:00:00.048" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 3 + "source": [ + "-- Code here:" + ] }, { + "attachments": {}, "cell_type": "markdown", + "metadata": { + "azdata_cell_guid": "c3cb4fa8-802c-4130-8740-2adf20ec6a15" + }, "source": [ "## QUESTION 4:  Thisbe\n", "\n", @@ -160,38 +157,57 @@ "**Part A:**   Write a query that compares the publication time with average reader ratings.\n", "\n", "**Part B:**  She wants the list ordered by year, then the book title" - ], - "metadata": { - "azdata_cell_guid": "c3cb4fa8-802c-4130-8740-2adf20ec6a15" - }, - "attachments": {} + ] }, { "cell_type": "code", - "source": [ - "-- Code here:" - ], + "execution_count": 4, "metadata": { "azdata_cell_guid": "164e0a22-349f-45ed-afe8-0753d5a8c6fc", "tags": [] }, "outputs": [ { - "output_type": "display_data", "data": { - "text/html": "Commands completed successfully." + "text/html": [ + "Commands completed successfully." + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" }, { - "output_type": "display_data", "data": { - "text/html": "Total execution time: 00:00:00.051" + "text/html": [ + "Total execution time: 00:00:00.051" + ] }, - "metadata": {} + "metadata": {}, + "output_type": "display_data" } ], - "execution_count": 4 + "source": [ + "-- Code here:" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "extensions": { + "vscode": { + "version": 1, + "views": [] + } + }, + "kernelspec": { + "display_name": "SQL", + "language": "sql", + "name": "SQL" + }, + "language_info": { + "name": "sql", + "version": "" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From d290b9c04be99a7c900d54ad98c0090b2d30346f Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Thu, 23 Oct 2025 19:45:18 -0500 Subject: [PATCH 21/22] 10232025 1945 --- .../exercises/SQL-Part-5-Exercises.ipynb | 30 +++++-- sql-part-5/studio/SQL-Part-5-Studio.ipynb | 82 ++++++++++++++++++- 2 files changed, 104 insertions(+), 8 deletions(-) diff --git a/sql-part-5/exercises/SQL-Part-5-Exercises.ipynb b/sql-part-5/exercises/SQL-Part-5-Exercises.ipynb index 140a43314..701f32ba0 100644 --- a/sql-part-5/exercises/SQL-Part-5-Exercises.ipynb +++ b/sql-part-5/exercises/SQL-Part-5-Exercises.ipynb @@ -24,7 +24,12 @@ } }, "outputs": [], - "source": [] + "source": [ + "create table Sep2025JunkDB.nick_ohanlon.planned_makes\n", + "(project_id int PRIMARY KEY identity(1,1),\n", + "project_name varchar(50),\n", + "status VARCHAR(10))" + ] }, { "cell_type": "markdown", @@ -42,7 +47,12 @@ } }, "outputs": [], - "source": [] + "source": [ + "insert into Sep2025JunkDB.nick_ohanlon.planned_makes (project_name,status)\n", + "values ('computer build','not started'),\n", + "('book maker','waiting'),\n", + "('tank build','waiting')" + ] }, { "cell_type": "markdown", @@ -62,7 +72,11 @@ } }, "outputs": [], - "source": [] + "source": [ + "update Sep2025JunkDB.nick_ohanlon.planned_makes\n", + "set status = 'finished'\n", + "where project_id = 1" + ] }, { "cell_type": "markdown", @@ -82,7 +96,11 @@ } }, "outputs": [], - "source": [] + "source": [ + "delete from\n", + "Sep2025JunkDB.nick_ohanlon.planned_makes\n", + "where project_id is '1'" + ] }, { "cell_type": "markdown", @@ -102,7 +120,9 @@ } }, "outputs": [], - "source": [] + "source": [ + "drop table Sep2025JunkDB.nick_ohanlon.planned_makes" + ] } ], "metadata": { diff --git a/sql-part-5/studio/SQL-Part-5-Studio.ipynb b/sql-part-5/studio/SQL-Part-5-Studio.ipynb index e57f8221f..716a6560c 100644 --- a/sql-part-5/studio/SQL-Part-5-Studio.ipynb +++ b/sql-part-5/studio/SQL-Part-5-Studio.ipynb @@ -63,7 +63,14 @@ }, "outputs": [], "source": [ - "-- Create the book table here. Update the name of the database and schema." + "CREATE table Sep2025JunkDB.nick_ohanlon.book\n", + "(book_id INT IDENTITY(1,1) PRIMARY KEY,\n", + " author_id INT,\n", + " title VARCHAR(255),\n", + " isbn INT,\n", + " available BIT,\n", + " genre_id INT\n", + ");" ] }, { @@ -87,7 +94,42 @@ }, "outputs": [], "source": [ - "-- Paste the book data values in this code box. Be sure to update database and schema names." + "INSERT INTO Sep2025JunkDB.nick_ohanlon.book(author_id, title, isbn, available, genre_id)\n", + "VALUES (2, 'A Midsummers Night Dream', 978149413, 1, 23),\n", + " (2, 'Romeo and Juliet', 988535196, 1, 3),\n", + "(1, 'The Golden Compass', 451664226, 1, 1),\n", + "(1, 'The Subtle Knife', 160419390, 1, 1),\n", + "(1, 'The Amber Spyglass', 94387895, 1, 1),\n", + "(3, 'The Alchemist', 464069772, 1, 2),\n", + "(4, 'And Then There Were None', 335973357, 1, 6),\n", + "(5, 'The Joy Luck Club', 990050329, 1, 10),\n", + "(5, 'The Moon Lady', 91720786, 1, 24),\n", + "(6, 'Sense and Sensibility', 156879860, 1, 2),\n", + "(6, 'Northanger Abbey', 951273178, 1, 3),\n", + "(6, 'Pride and Prejudice', 415886839, 1, 3),\n", + "(6, 'Mansfield Park', 188534067, 1, 3),\n", + "(6, 'Emma', 994896202, 1, 3),\n", + "(6, 'Persuasion', 28150097, 1, 3),\n", + "(6, 'Lady Susan', 230962926, 1, 3),\n", + "(7, 'Wuthering Heights', 280569946, 1, 3),\n", + "(8, 'The Handmaids Tale', 639239663, 1, 5),\n", + "(8, 'The Testaments', 826875490, 1, 5),\n", + "(9, 'The Parable of the Sower', 283359358, 1, 5),\n", + "(10, 'Little Women', 495409887, 1, 23),\n", + "(11, 'Still Life', 455128657, 1, 6),\n", + "(11, 'A Fatal Grace', 832517012, 1, 6),\n", + "(11, 'The Cruelest Month', 419285319, 1, 6),\n", + "(11, 'The Murder Stone', 656621400, 1, 6),\n", + "(11, 'The Brutal Telling', 144255852, 1, 6),\n", + "(11, 'Bury Your Dead', 208180961, 1, 6),\n", + "(11, 'A Trick of the Light', 93451531, 1, 6),\n", + "(12, 'Midnights Children', 881082293, 1, 10),\n", + "(13, 'Dont Let the Pigeon Drive the Bus!', 18409532, 1, 24),\n", + "(14, 'Beezus and Ramona', 744412630, 1, 24),\n", + "(15, 'Organic Chemistry', 604328803, 1, 25),\n", + "(16, 'I Know Why the Caged Bird Sings', 909947112, 1, 12),\n", + "(17, 'Beloved', 46736233, 1, 10),\n", + "(18, 'Brassbones and Rainbows', 330608463, 1, 26);" ] }, { @@ -109,7 +151,41 @@ }, "outputs": [], "source": [ - "-- test your book table here." + "1\t2\tA Midsummers Night Dream\t978149413\t1\t23\n", + "2\t2\tRomeo and Juliet\t988535196\t1\t3\n", + "3\t1\tThe Golden Compass\t451664226\t1\t1\n", + "4\t1\tThe Subtle Knife\t160419390\t1\t1\n", + "5\t1\tThe Amber Spyglass\t94387895\t1\t1\n", + "6\t3\tThe Alchemist\t464069772\t1\t2\n", + "7\t4\tAnd Then There Were None\t335973357\t1\t6\n", + "8\t5\tThe Joy Luck Club\t990050329\t1\t10\n", + "9\t5\tThe Moon Lady\t91720786\t1\t24\n", + "10\t6\tSense and Sensibility\t156879860\t1\t2\n", + "11\t6\tNorthanger Abbey\t951273178\t1\t3\n", + "12\t6\tPride and Prejudice\t415886839\t1\t3\n", + "13\t6\tMansfield Park\t188534067\t1\t3\n", + "14\t6\tEmma\t994896202\t1\t3\n", + "15\t6\tPersuasion\t28150097\t1\t3\n", + "16\t6\tLady Susan\t230962926\t1\t3\n", + "17\t7\tWuthering Heights\t280569946\t1\t3\n", + "18\t8\tThe Handmaids Tale\t639239663\t1\t5\n", + "19\t8\tThe Testaments\t826875490\t1\t5\n", + "20\t9\tThe Parable of the Sower\t283359358\t1\t5\n", + "21\t10\tLittle Women\t495409887\t1\t23\n", + "22\t11\tStill Life\t455128657\t1\t6\n", + "23\t11\tA Fatal Grace\t832517012\t1\t6\n", + "24\t11\tThe Cruelest Month\t419285319\t1\t6\n", + "25\t11\tThe Murder Stone\t656621400\t1\t6\n", + "26\t11\tThe Brutal Telling\t144255852\t1\t6\n", + "27\t11\tBury Your Dead\t208180961\t1\t6\n", + "28\t11\tA Trick of the Light\t93451531\t1\t6\n", + "29\t12\tMidnights Children\t881082293\t1\t10\n", + "30\t13\tDont Let the Pigeon Drive the Bus!\t18409532\t1\t24\n", + "31\t14\tBeezus and Ramona\t744412630\t1\t24\n", + "32\t15\tOrganic Chemistry\t604328803\t1\t25\n", + "33\t16\tI Know Why the Caged Bird Sings\t909947112\t1\t12\n", + "34\t17\tBeloved\t46736233\t1\t10\n", + "35\t18\tBrassbones and Rainbows\t330608463\t1\t26" ] }, { From ec88d08cbb2b6c93e2ddec92a3fbd219beb50ef9 Mon Sep 17 00:00:00 2001 From: nohanlon3254 Date: Wed, 29 Oct 2025 20:47:42 -0500 Subject: [PATCH 22/22] 10/2/2025 --- data-and-variables/exercises/exercises.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/data-and-variables/exercises/exercises.py b/data-and-variables/exercises/exercises.py index a068e42c1..30321cbb0 100644 --- a/data-and-variables/exercises/exercises.py +++ b/data-and-variables/exercises/exercises.py @@ -1,7 +1,20 @@ # 1. Declare and assign the variables here: - +shuttle_name = 'Determination' +shuttle_speed_mph = 17500 +distance_to_mars_km = 225000000 +distance_to_moon_km = 38400 +MILES_PER_KM = 0.621 # 2. Use print() to print the 'type' each variable. Print one item per line. - +print(type(shuttle_name)) +print(type(shuttle_speed_mph)) +print(type(distance_to_mars_km)) +print(type(distance_to_moon_km)) # Code your solution to exercises 3 and 4 here: - +miles_to_mars = distance_to_mars_km * MILES_PER_KM +hours_to_mars = miles_to_mars / shuttle_speed_mph +days_to_mars = hours_to_mars / 24 # Code your solution to exercise 5 here +miles_to_moon = distance_to_moon_km * MILES_PER_KM +hours_to_moon = miles_to_moon / shuttle_speed_mph +days_to_moon = hours_to_moon / 24 +print(shuttle_name + " will take " + days_to_moon + " days to reach the Moon.") \ No newline at end of file