forked from dafrenchyman/PythonProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
assignment 2 added #2
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
Open
BitaEt
wants to merge
4
commits into
master
Choose a base branch
from
assignment2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| create index idx_batter_counts on baseball.batter_counts(game_id); | ||
| create index idx_game on baseball.game(game_id); | ||
|
|
||
| --note: commented out after code buddy reviewed this | ||
| ---create table baseball.results (batter numeric, annual_batting_average double PRECISION, historic_batting_average double precision, rolling_batting_average double PRECISION); | ||
|
|
||
| Question 1 | ||
|
|
||
| annual | ||
| create table baseball.annual_batting_average (select batter, batting_average from( | ||
| select btc.batter, sum(btc.hit)/sum(btc.atBat) as batting_average, extract(YEAR from gm.local_date) as year | ||
| from baseball.batter_counts btc | ||
| left join baseball.game gm | ||
| on btc.game_id = gm.game_id | ||
| group by (btc.batter), year | ||
| having sum(btc.atBat) > 0 | ||
| order by (btc.batter), year) as aa) | ||
|
|
||
|
|
||
| total | ||
| create table baseball.total_batting_average (select batter, sum(hit)/sum(atBat) as batting_average | ||
| from baseball.batter_counts | ||
| group by batter | ||
| having sum(atBat) >0); | ||
|
|
||
|
|
||
| Question 2 | ||
|
|
||
| create table baseball.rolling_batting_average (with t1 as (select btc.batter, max(gm.local_date) as max from baseball.batter_counts btc | ||
| left join baseball.game gm | ||
| on btc.game_id = gm.game_id | ||
| group by btc.batter), | ||
| t2 as (select btc.batter, sum(btc.hit)/sum(btc.atBat) as batting_average, gm.local_date | ||
| from baseball.batter_counts btc | ||
| left join baseball.game gm | ||
| on btc.game_id = gm.game_id | ||
| group by btc.batter, btc.game_id | ||
| having sum(btc.atBat)>0) | ||
| select t2.batter , avg(t2.batting_average) from t2 | ||
| right join t1 on t2.batter = t1.batter | ||
| where t2.local_date > date_add(t1.max, INTERVAL -100 DAY) | ||
| group by t1.batter); | ||
|
|
||
| --Explanation about temporary tables: | ||
| --I just created those since I thought we have to store the answers in a new table, but if not those tables are not needed and can simply be removed from the query | ||
|
|
||
| drop table baseball.annual_batting_average; | ||
| drop table baseball.total_batting_average; | ||
| drop table baseball.rolling_batting_average; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to comment out these labels for the code because it won't run if you don't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi tom, I changed the code a little bit and created the tables at the beginning of the queries, so I commented out this one since I no longer need it, can you check it one more time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I commented out that table that I initially created, and stored all results in their own tables (baseball. annual_batting_average, baseball.total_batting_average, baseball.rolling_batting_average). this should work now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also bit make sure to drop your temporary tables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bita*