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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions Homework1.txt

This file was deleted.

116 changes: 116 additions & 0 deletions Homework2.txt
Original file line number Diff line number Diff line change
@@ -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 |
+--------+--------+----------+
37 changes: 16 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@

# 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 goal of this module is to familiarize yourself with aggregations, groups, and sub-queries in SQL.

- use of the SELECT clause to specify which fields you want to query

- use of the FROM clause to specify which tables you want to query, and

- use of the WHERE clause to specify which conditions the query will use to query rows in a table.
## 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.

#### Question: Design the following queries, using the lyrics.sql schema:
- List the TitleID, Title, and UPC of any titles whose UPC end with '2'

- List the Title, UPC and Genre of all CD titles. (Titles table)
- 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.

- List all of the information of CD(s) produced by the artist whose ArtistID is 2. (Titles table)
- List the TitleID, TrackNum, and TrackTitle of all tracks with 'Song' at the beginning of the TrackTitle

- List the First Name, Last Name, HomePhone and Email address of all members. (Members table)
#### Part 2

- List the Member ID of all male members. (Members table)
- Report the average, shortest and longest track length in minutes of all tracks.

- List the Member ID and Country of all members in Canada. (Members table)
- Report the number of male members who are in US.

- 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 tracks for each TitleID

- Report the total time in minutes for each titleid

- Report the number of members by state and gender. Sort the results by the region