Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8654780
I added text to about-me.md
JoseRMatos Aug 22, 2019
35bd6d3
Jose made some changes
JoseRMatos Aug 22, 2019
4b79c4a
I add my info into the about-me.md file
JoseRMatos Aug 22, 2019
fd3f822
Add Lab MySQL Selecg solutions.sql
JoseRMatos Sep 15, 2019
a03b9e8
Addin lab-list-comprehensions main.ipynb
JoseRMatos Sep 15, 2019
a995052
Adding Dicts, Sets and Tuples
JoseRMatos Sep 15, 2019
fda62d6
Adding lab-string-operations Challenge 1 need to finish challenge 2
JoseRMatos Sep 15, 2019
ab42202
Adding lab-advanced-regex
JoseRMatos Sep 15, 2019
47e1d11
Lab | Functional Programming, Lab | Lambda Function, Lab | Error Hand…
JoseRMatos Sep 15, 2019
41dba92
Lab Advanced MySQL solutions
JoseRMatos Sep 15, 2019
53b011a
Adding Lab | String Ops and Bag of Words, Challenge 2
JoseRMatos Sep 17, 2019
4baae21
Adding Lab Functional Programing Q1
JoseRMatos Sep 17, 2019
5e48b53
Lab Numpy
JoseRMatos Sep 19, 2019
bc42ed3
Lab Intro Pandas
JoseRMatos Sep 20, 2019
d2474f4
Lab import-export
JoseRMatos Sep 21, 2019
040ee7a
Lab data Cleaning
JoseRMatos Sep 21, 2019
82afb19
Lambda Function
JoseRMatos Sep 22, 2019
ee424f6
Pandas Project
JoseRMatos Sep 28, 2019
f1ac868
lab-parsiong-api 'iNaturalist_API'
JoseRMatos Oct 1, 2019
5e50fca
lab-api-scavenger-game
JoseRMatos Oct 2, 2019
b700b97
lab-api-scavenger-game
JoseRMatos Oct 2, 2019
d8a36d9
lab-parallelization
JoseRMatos Oct 12, 2019
d66bb09
Subsetting and Descriptive Stats
JoseRMatos Oct 17, 2019
5c0b515
Lab | Subsetting and Descriptive Stats, Lab | Introduction to Scipy, …
JoseRMatos Oct 27, 2019
8f1445c
lab-discrete-probability-distribution
JoseRMatos Nov 18, 2019
04dc0fa
lab-plotting-multiple-data-series
JoseRMatos Nov 18, 2019
eacfa28
lab-intro-to-ml
JoseRMatos Dec 21, 2019
69aa45f
lab-supervised-learning-feature-extraction
JoseRMatos Dec 30, 2019
4dd1262
“lab-intro-to-sklearn”
JoseRMatos Jan 4, 2020
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
3 changes: 3 additions & 0 deletions module-1/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/local/opt/python/bin/python3.7"
}
101 changes: 101 additions & 0 deletions module-1/lab-advanced-mysql/your-code/solutions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
-- Lab | Advanced MySQL

-- Challenge 1 - Most Profiting Authors
-- Step 1: Calculate the royalties of each sales for each author
SELECT
`Title ID`, `Author ID`, `Royalty`

FROM(
SELECT
titleauthor.title_id AS 'Title ID',
titleauthor.au_id AS 'Author ID',
titles.price * sales.qty * titles.royalty/100 *titleauthor.royaltyper/100 AS 'Royalty'

FROM titleauthor
JOIN titles
ON titleauthor.title_id = titles.title_id
JOIN sales
ON titleauthor.title_id = sales.title_id
)
AS A GROUP BY `Author ID`, `Title ID`, Royalty
;

-- Step 2: Aggregate the total royalties for each title for each author
SELECT
`Title ID`, `Author ID`, `Royalty`

FROM(
SELECT
titleauthor.title_id AS 'Title ID',
titleauthor.au_id AS 'Author ID',
SUM(titles.price * sales.qty * titles.royalty/100 *titleauthor.royaltyper/100) OVER(PARTITION BY titleauthor.au_id) AS 'Royalty'

FROM titleauthor
JOIN titles
ON titleauthor.title_id = titles.title_id
JOIN sales
ON titleauthor.title_id = sales.title_id
)
AS A GROUP BY `Author ID`, `Title ID`, Royalty
;

-- Step 3: Calculate the total profits of each author
SELECT
`Author ID`, `Profit`

FROM(
SELECT
titleauthor.title_id AS 'Title ID',
titleauthor.au_id AS 'Author ID',
SUM(titles.price * sales.qty * titles.royalty/100 *titleauthor.royaltyper/100 + titles.advance) OVER(PARTITION BY titleauthor.au_id) AS 'Profit'

FROM titleauthor
JOIN titles
ON titleauthor.title_id = titles.title_id
JOIN sales
ON titleauthor.title_id = sales.title_id
)
AS A GROUP BY `Author ID`, Profit
ORDER BY Profit DESC
LIMIT 3;

-- Challenge 2 - Alternative Solution

CREATE TEMPORARY TABLE temp1

SELECT
titleauthor.title_id AS 'Title ID',
titleauthor.au_id AS 'Author ID',
SUM(titles.price * sales.qty * titles.royalty/100 *titleauthor.royaltyper/100 + titles.advance) OVER(PARTITION BY titleauthor.au_id) AS 'Profit'

FROM titleauthor
JOIN titles
ON titleauthor.title_id = titles.title_id
JOIN sales
ON titleauthor.title_id = sales.title_id
;

SELECT
`Author ID`, `Profit`
FROM
temp1
GROUP BY `Author ID`, Profit
ORDER BY Profit DESC
LIMIT 3;

-- Challenge 3

CREATE TABLE most_profiting_authors AS

SELECT
distinct titleauthor.au_id AS 'Author ID',
SUM(titles.price * sales.qty * titles.royalty/100 *titleauthor.royaltyper/100 + titles.advance) OVER(PARTITION BY titleauthor.au_id) AS 'Profit'

FROM titleauthor
JOIN titles
ON titleauthor.title_id = titles.title_id
JOIN sales
ON titleauthor.title_id = sales.title_id
;

SELECT * FROM most_profiting_authors;
Loading