From 8af9d98c621ef4fb77c52c9273e3ce5b681feebc Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 10:59:27 -0700 Subject: [PATCH 1/7] Rename README.md to Homework2.md --- README.md => Homework2.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => Homework2.md (100%) diff --git a/README.md b/Homework2.md similarity index 100% rename from README.md rename to Homework2.md From 053377f59263ebb4d72b3ef450eb2d8b11044189 Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 10:59:51 -0700 Subject: [PATCH 2/7] Update Homework2.md --- Homework2.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Homework2.md b/Homework2.md index 20de9b2..03ce13f 100644 --- a/Homework2.md +++ b/Homework2.md @@ -1,8 +1,5 @@ - # Homework 1 - - ## Purpose Purpose @@ -33,5 +30,3 @@ These are the basic commands that will make up your foundational knowledge of SQ - List the Member ID and Country of all members in Canada. (Members table) - List the first name, last name, and region of all members from Virginia who either have a work phone or an email address. (Members Table) - - From 1ec66dbeb456b963f9a1b1a1d33658684350a11e Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 11:00:28 -0700 Subject: [PATCH 3/7] Update Homework2.md --- Homework2.md | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Homework2.md b/Homework2.md index 03ce13f..73bf495 100644 --- a/Homework2.md +++ b/Homework2.md @@ -1,32 +1,39 @@ -# Homework 1 +# Homework 2 ## Purpose Purpose -The purpose of this assignment is to demonstrate knowledge of the basic syntax of a SQL query. Specifically, you will be asked to demonstrate: +The purpose of this assignment is to -- use of the SELECT clause to specify which fields you want to query +- review the basic syntax of a SQL query, and -- use of the FROM clause to specify which tables you want to query, and +- use aggregate functions to group the values of an entire table or several rows to form a single summary value. -- use of the WHERE clause to specify which conditions the query will use to query rows in a table. +Aggregations a very powerful means to get statistics about large amounts of data. Oftentimes it isn't enough to query records, you may need to calculate summaries of a table or subgroups of a table. Aggregation operations group values from multiple rows together, and can perform variety of operations on the grouped data to return a single result. +## Tasks -These are the basic commands that will make up your foundational knowledge of SQL. There are other clauses besides SELECT, FROM, and WHERE, but by building up your knowledge of these basic clauses, you will have constructed a foundation upon which to base your knowledge of SQL. +### Question: Design the following queries, using the lyrics.sql schema: +#### Part 1 +- List the first name, last name, home phone, and gender of all members from Georgia who either have a home phone in area code 822 or are female -## Tasks +- List all the information of tracks that do not have an MP3. + +- List the TitleID, Title, and UPC of any titles whose UPC end with '2' + +- List the artist name and web address of any artists who has a web address. Rename the attributes artistname, webaddress as Artist Name, Web Address. -#### Question: Design the following queries, using the lyrics.sql schema: +- List the TitleID, TrackNum, and TrackTitle of all tracks with 'Song' at the beginning of the TrackTitle -- List the Title, UPC and Genre of all CD titles. (Titles table) +#### Part 2 -- List all of the information of CD(s) produced by the artist whose ArtistID is 2. (Titles table) +- Report the average, shortest and longest track length in minutes of all tracks. -- List the First Name, Last Name, HomePhone and Email address of all members. (Members table) +- Report the number of male members who are in US. -- List the Member ID of all male members. (Members table) +- Report the number of tracks for each TitleID -- List the Member ID and Country of all members in Canada. (Members table) +- Report the total time in minutes for each titleid -- List the first name, last name, and region of all members from Virginia who either have a work phone or an email address. (Members Table) +- Report the number of members by state and gender. Sort the results by the region From ff15e82397bf072b905a8057d432e02b83a83d43 Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 11:06:45 -0700 Subject: [PATCH 4/7] Rename Homework2.md to README.md --- Homework2.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Homework2.md => README.md (100%) diff --git a/Homework2.md b/README.md similarity index 100% rename from Homework2.md rename to README.md From 15ba17957d7dd11aa478717d3fb695e4ec3c1ce0 Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 11:16:44 -0700 Subject: [PATCH 5/7] Add files via upload --- Homework2.txt | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Homework2.txt diff --git a/Homework2.txt b/Homework2.txt new file mode 100644 index 0000000..208988d --- /dev/null +++ b/Homework2.txt @@ -0,0 +1,116 @@ +select firstname, lastname, homephone, gender from members where Region = 'GA' and Homephone = '822' or Gender = 'F'; ++-----------+-----------+------------+--------+ +| firstname | lastname | homephone | gender | ++-----------+-----------+------------+--------+ +| Mary | Chrisman | 3171820387 | F | +| Michelle | Henderson | 8221928273 | F | +| Carol | Wanner | 6831223944 | F | +| Caroline | Kale | 7321223742 | F | +| Bonnie | Taft | 3721223292 | F | ++-----------+-----------+------------+--------+ + + select * from tracks where MP3 = '0'; ++---------+----------+------------+---------------+------+---------+ +| TitleID | TrackNum | TrackTitle | LengthSeconds | MP3 | RealAud | ++---------+----------+------------+---------------+------+---------+ +| 3 | 7 | Wooden Man | 314 | 0 | 0 | +| 3 | 8 | UPS | 97 | 0 | 0 | +| 3 | 9 | Empty | 182 | 0 | 0 | +| 3 | 10 | Burrito | 65 | 0 | 0 | ++---------+----------+------------+---------------+------+---------+ + +select titleid, title, upc from titles where UPC like '%2'; ++---------+-----------------+------------+ +| titleid | title | upc | ++---------+-----------------+------------+ +| 3 | Smell the Glove | 1283772282 | +| 4 | Time Flies | 1882344222 | +| 5 | Neurotic Sequel | 2828830202 | ++---------+-----------------+------------+ + + +select artistname as 'ArtistName', webaddress as 'WebAddress' from artists where webaddress <> 'NULL'; ++----------------+--------------------------+ +| ArtistName | WebAddress | ++----------------+--------------------------+ +| The Neurotics | www.theneurotics.com | +| Sonata | www.classical.com/sonata | +| Jose MacArthur | www.josemacarthur.com | +| Today | www.today.com | +| 21 West Elm | www.21westelm.com | ++----------------+--------------------------+ + +select titleid, tracknum, tracktitle from tracks where tracktitle like 'Song%'; ++---------+----------+----------------+ +| titleid | tracknum | tracktitle | ++---------+----------+----------------+ +| 5 | 1 | Song 1 | +| 5 | 2 | Song 2 | +| 5 | 3 | Song 3 | +| 5 | 4 | Song 4 | +| 5 | 5 | Song 5 | +| 5 | 6 | Song 6 | +| 5 | 7 | Song 7 | +| 5 | 8 | Song 8 | +| 5 | 9 | Song 8 and 1/2 | ++---------+----------+----------------+ + +select avg(lengthseconds/60) as 'Average', min(lengthseconds/60) as 'Shortest', max(lengthseconds/60) as 'Longest' from tracks; ++------------+----------+---------+ +| Average | Shortest | Longest | ++------------+----------+---------+ +| 4.60133333 | 0.7500 | 13.6833 | ++------------+----------+---------+ + +select count(Gender) as 'Male Members who are in US' from members where Gender = 'M' and Country = 'USA'; ++----------------------------+ +| Male Members who are in US | ++----------------------------+ +| 16 | ++----------------------------+ + +select titleid, count(tracknum) as 'Number of Tracks' from tracks group by titleid; ++---------+------------------+ +| titleid | Number of Tracks | ++---------+------------------+ +| 1 | 8 | +| 3 | 10 | +| 4 | 10 | +| 5 | 9 | +| 6 | 5 | +| 7 | 8 | ++---------+------------------+ + +select titleid, sum(lengthseconds/60) as 'Total time in Minutes' from tracks group by titleid; ++---------+-----------------------+ +| titleid | Total time in Minutes | ++---------+-----------------------+ +| 1 | 37.2833 | +| 3 | 35.4833 | +| 4 | 36.8832 | +| 5 | 34.7832 | +| 6 | 44.3667 | +| 7 | 41.2666 | ++---------+-----------------------+ + +select region, gender, count(*) from members group by region, gender; ++--------+--------+----------+ +| region | gender | count(*) | ++--------+--------+----------+ +| IN | M | 1 | +| CA | M | 1 | +| IN | F | 1 | +| TX | M | 2 | +| GA | M | 2 | +| GA | F | 1 | +| NY | M | 2 | +| NC | M | 1 | +| TX | F | 1 | +| ONT | M | 2 | +| VA | M | 2 | +| VA | F | 1 | +| VT | F | 1 | +| IL | M | 1 | +| VT | M | 2 | +| OH | M | 2 | ++--------+--------+----------+ \ No newline at end of file From 2b8c8c740e5233f29ce59a500c8d0838936251e9 Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 11:17:07 -0700 Subject: [PATCH 6/7] Delete Homework1.txt --- Homework1.txt | 87 --------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 Homework1.txt diff --git a/Homework1.txt b/Homework1.txt deleted file mode 100644 index d97cf17..0000000 --- a/Homework1.txt +++ /dev/null @@ -1,87 +0,0 @@ -select title, upc, genre from titles; -+--------------------+------------+-------------+ -| title | upc | genre | -+--------------------+------------+-------------+ -| Meet the Neurotics | 2727366627 | alternative | -| Smell the Glove | 1283772282 | metal | -| Time Flies | 1882344222 | alternative | -| Neurotic Sequel | 2828830202 | alternative | -| Sonatas | 3999320021 | classical | -| Louis at the Keys | 3838227111 | jazz | -+--------------------+------------+-------------+ - -select * from titles where artistid = '2'; -+---------+----------+-------------------+----------+------------+-------+ -| TitleID | ArtistID | Title | StudioID | UPC | Genre | -+---------+----------+-------------------+----------+------------+-------+ -| 7 | 2 | Louis at the Keys | 3 | 3838227111 | jazz | -+---------+----------+-------------------+----------+------------+-------+ - -select firstname, lastname, homephone, email from members; -+-----------+-----------+------------+------------------------+ -| firstname | lastname | homephone | email | -+-----------+-----------+------------+------------------------+ -| Roberto | Alvarez | 7651552983 | ral@mightyhostl.com | -| Jose | MacArthur | 6331289393 | jmac@dowop.com | -| Mary | Chrisman | 3171820387 | mjc17@daviscorp.com | -| Warren | Boyer | 8221722883 | wbman@uptime.net | -| Doug | Finney | 9821222929 | fennyd@bitspeed.com | -| Terry | Irving | 5411252093 | NULL | -| Michelle | Henderson | 8221928273 | NULL | -| William | Morrow | 9981722928 | wmorrow@wmorrow.com | -| Frank | Payne | 9981737464 | NULL | -| Aiden | Franks | 8321729283 | kosmo@ispl.com | -| Bryce | Sanders | 6441824283 | bs@cookery.com | -| Carol | Wanner | 6831223944 | NULL | -| Brian | Ranier | 6231842933 | NULL | -| Marcellin | Lambert | 8331929302 | mlambert@corkscrew.com | -| Caroline | Kale | 7321223742 | NULL | -| Kerry | Fernandez | 2211229384 | NULL | -| Tony | Wong | 3311692832 | twong@tamilla.org | -| Bonnie | Taft | 3721223292 | taffygirl@signon.com | -| Louis | Holiday | 1451223838 | NULL | -| Bobby | Crum | 1831828211 | NULL | -| Vic | Cleaver | 8111839292 | NULL | -| Roberto | Goe | 2771123943 | NULL | -| Davis | Goodman | 2771152882 | goody@irvingnet.com | -+-----------+-----------+------------+------------------------+ - -select memberid, gender from members where Gender = 'M'; -+----------+--------+ -| memberid | gender | -+----------+--------+ -| 10 | M | -| 31 | M | -| 15 | M | -| 32 | M | -| 19 | M | -| 34 | M | -| 29 | M | -| 35 | M | -| 3 | M | -| 33 | M | -| 7 | M | -| 9 | M | -| 26 | M | -| 20 | M | -| 22 | M | -| 28 | M | -| 30 | M | -| 36 | M | -+----------+--------+ - -select memberid, country from members where Country = 'Canada'; -+----------+---------+ -| memberid | country | -+----------+---------+ -| 33 | Canada | -| 26 | Canada | -+----------+---------+ - -select firstname, lastname, region, email, workphone from members where email = 'mlambert@corkscrew.com' or workphone = '2211223939'; -+-----------+-----------+--------+------------------------+------------+ -| firstname | lastname | region | email | workphone | -+-----------+-----------+--------+------------------------+------------+ -| Marcellin | Lambert | VA | mlambert@corkscrew.com | NULL | -| Kerry | Fernandez | VA | NULL | 2211223939 | -+-----------+-----------+--------+------------------------+------------+ From 16d1d7ada8fd55e3ba69279839ed53bfe492e4f6 Mon Sep 17 00:00:00 2001 From: branden12 Date: Mon, 22 May 2023 11:34:54 -0700 Subject: [PATCH 7/7] Update README.md --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 73bf495..d16cf93 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,8 @@ ## Purpose -Purpose +The goal of this module is to familiarize yourself with aggregations, groups, and sub-queries in SQL. -The purpose of this assignment is to - -- review the basic syntax of a SQL query, and - -- use aggregate functions to group the values of an entire table or several rows to form a single summary value. - -Aggregations a very powerful means to get statistics about large amounts of data. Oftentimes it isn't enough to query records, you may need to calculate summaries of a table or subgroups of a table. Aggregation operations group values from multiple rows together, and can perform variety of operations on the grouped data to return a single result. ## Tasks ### Question: Design the following queries, using the lyrics.sql schema: