Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added answers from Ivy #4

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9bb692f
Completed Tasks
ivywsip Oct 14, 2019
bab582a
Escaped room Ivy!
ivywsip Oct 18, 2019
d15215b
Completed lasbs
ivywsip Oct 18, 2019
accf341
Completed labs
ivywsip Oct 18, 2019
5c3f90c
Escape room game from Ivy
ivywsip Oct 19, 2019
10adbe6
Escape room Ivy
ivywsip Oct 20, 2019
c381f60
LAB SQL - Selection with answers
ivywsip Oct 21, 2019
f9d2962
ADDED ANSWERS FROM IVY
ivywsip Oct 21, 2019
bf20f70
Added answers from Ivy
ivywsip Oct 21, 2019
55fcc64
With answers
ivywsip Oct 22, 2019
f088936
Added answers
ivywsip Oct 22, 2019
5c4c6e6
ADDED ANSWER
ivywsip Oct 22, 2019
47df260
ADDED SOLUTIONS
ivywsip Oct 22, 2019
cbaf9f3
added solutions
ivywsip Oct 22, 2019
17243c8
Merge remote-tracking branch 'upstream/master'
ivywsip Oct 24, 2019
8d48c45
Merge remote-tracking branch 'upstream/master'
ivywsip Oct 24, 2019
db859d7
Added answers
ivywsip Oct 27, 2019
35730ef
Added Answers
ivywsip Oct 27, 2019
96415d0
Updated answers
ivywsip Oct 27, 2019
58c8845
Merge remote-tracking branch 'upstream/master'
ivywsip Oct 28, 2019
dd16668
Merge remote-tracking branch 'upstream/master'
ivywsip Oct 29, 2019
52f644e
Added answers
ivywsip Nov 5, 2019
269470d
Merge remote-tracking branch 'upstream/master'
ivywsip Nov 5, 2019
fcd9ab5
Tableau project added
ivywsip Nov 10, 2019
89cd7c6
Update README.md
ivywsip Nov 10, 2019
bab7a37
Tableau project updated
ivywsip Nov 10, 2019
1b973c0
Update Read.md
ivywsip Nov 10, 2019
09555b4
Merge branch 'master' of https://github.com/ivywsip/data-ber-10-19
ivywsip Nov 17, 2019
1233bb6
Added project
ivywsip Nov 17, 2019
a1531ab
Added all files in the project
ivywsip Nov 23, 2019
66f2dbd
Updated readme
ivywsip Nov 23, 2019
64dbe79
Updated Readme
ivywsip Nov 23, 2019
204ef5f
Readme
ivywsip Nov 23, 2019
d82fb01
updated readme
ivywsip Nov 23, 2019
54b8c66
Updated Readme
ivywsip Nov 23, 2019
d46cf93
Updated Readme
ivywsip Nov 23, 2019
1f26efd
Merge remote-tracking branch 'upstream/master'
ivywsip Dec 20, 2019
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
120 changes: 120 additions & 0 deletions module-1_labs/LABS_sql_selection.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

-- Challenge 1

SELECT
client_id
FROM bank.client
WHERE district_id =1
LIMIT 5;


-- Challenge 2

SELECT
client_id
FROM bank.client
WHERE district_id =72
ORDER BY client_id DESC
LIMIT 1;


-- Challenge 3

DESC loan;

SELECT
amount
FROM bank.loan
ORDER BY amount
LIMIT 3;


-- Challenge 4

SELECT
loan.status
FROM bank.loan
GROUP BY loan.status
ORDER BY loan.status;

-- Challenge 5
DESC loan;

-- highest payment
SELECT
loan_id,
payments
FROM bank.loan
ORDER BY payments DESC
LIMIT 10;

-- lowest payment
SELECT
loan_id,
payments
FROM bank.loan
ORDER BY payments
LIMIT 1;

-- Challenge 6
SELECT
account_id,
amount
FROM bank.loan
ORDER BY account_id
LIMIT 5;

-- Challenge 7

SELECT
account_id
FROM bank.loan
WHERE duration = 60
ORDER BY amount
LIMIT 5;

-- Challenge 8

SELECT
k_symbol
FROM bank.order
GROUP BY k_symbol
ORDER BY k_symbol;

-- Challenge 9

SELECT
order_id
FROM bank.order
WHERE account_id = 34;

-- Challenge 10

SELECT
account_id
FROM bank.order
WHERE
order_id >= 29540
AND order_id <= 29560
GROUP BY account_id
ORDER BY account_id;

-- Challenge 11

SELECT
amount
FROM bank.order
WHERE
account_to = 30067122;

-- Challenge 12

SELECT
trans_id,
trans.date,
trans.type,
amount
FROM bank.trans
WHERE account_id = 793
ORDER BY trans.date DESC
LIMIT 10;
Original file line number Diff line number Diff line change
@@ -1,4 +1,67 @@
-- Challenge 1
<<<<<<< HEAD
CREATE TEMPORARY TABLE royalty_sales (
SELECT
s.title_id AS Title_ID,
ta.au_id AS Author_ID,
t.advance AS Advance,
ta.royaltyper AS Royaltyper,
(t.advance*ta.royaltyper/100) AS Splited_advance,
SUM(t.price*s.qty*t.royalty/100*ta.royaltyper/100) AS Royalty_per_sale
FROM titles t
JOIN sales s
ON s.title_id = t.title_id
JOIN titleauthor ta
ON ta.title_id = t.title_id
GROUP BY 1,2
ORDER BY 5 DESC);

SELECT
rs.Author_ID,
a.au_lname,
a.au_fname,
ROUND(SUM(Splited_advance)+SUM(Royalty_per_sale),2) AS Profit
FROM royalty_sales rs
JOIN authors a
ON a.au_id = rs.Author_ID
GROUP BY 1
ORDER BY 4 DESC;




-- Challenge 3

CREATE TABLE most_profiting_authors (
WITH royalty_sales AS (
SELECT
s.title_id AS Title_ID,
ta.au_id AS Author_ID,
t.advance AS Advance,
ta.royaltyper AS Royaltyper,
(t.advance*ta.royaltyper/100) AS Splited_advance,
SUM(t.price*s.qty*t.royalty/100*ta.royaltyper/100) AS Royalty_per_sale
FROM titles t
JOIN sales s
ON s.title_id = t.title_id
JOIN titleauthor ta
ON ta.title_id = t.title_id
GROUP BY 1,2
ORDER BY 5 DESC)
SELECT
rs.Author_ID AS "Author ID",
ROUND(SUM(Splited_advance)+SUM(Royalty_per_sale),2) AS Profits
FROM royalty_sales rs
JOIN authors a
ON a.au_id = rs.Author_ID
GROUP BY 1
ORDER BY 2 DESC
LIMIT 3);


SELECT*
FROM most_profiting_authors;
=======

-- Step 1
select t.title_id, t.price, t.advance, t.royalty, s.qty, a.au_id, au_lname, au_fname, ta.royaltyper, (t.price * s.qty * t.royalty * ta.royaltyper / 10000) as ROYALTIES
Expand Down Expand Up @@ -70,3 +133,4 @@ inner join authors a on a.au_id = tmp2.au_id
group by tmp2.au_id
order by PROFITS desc
limit 3;
>>>>>>> upstream/master
Loading