-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5ccc2e
commit aaa2d4d
Showing
16 changed files
with
16,167 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains 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,69 @@ | ||
\documentclass[USenglish,final,authoryear,12pt]{article} | ||
|
||
|
||
|
||
\usepackage{amsmath} | ||
\usepackage[a4paper]{geometry} | ||
\geometry{ | ||
a4paper, | ||
total={210mm,297mm}, | ||
left=20mm, | ||
right=20mm, | ||
top=20mm, | ||
bottom=20mm, | ||
} | ||
|
||
\usepackage{sectsty} | ||
\usepackage{cancel} %need to use this | ||
\usepackage{babel} | ||
%\allsectionsfont{\normalfont\sffamily\bfseries} | ||
\usepackage{graphicx} | ||
\usepackage{caption} | ||
\usepackage{subcaption} | ||
\usepackage{longtable} | ||
%\begin{figure}[h] | ||
% \centering | ||
% \includegraphics[scale=0.5]{Image1.png} | ||
% \caption{Size of observable universe comparison between standard model of cosmology with inflation and without inflation [1].} | ||
%\end{figure} | ||
|
||
\begin{document} | ||
\textbf{\LARGE Exercise Sheet 1}\newline | ||
Solutions on the next page | ||
\section{} | ||
Perform the following tasks on the Training.db included in the attachments. | ||
\begin{enumerate} | ||
\item Using the Data Source from Path option in DataGrip, read in the Training.db database. This database is an SQLite database so DataGrip may prompt you to download the necessary drivers. | ||
\item Read the first 10 rows from each table in the database. | ||
\item Read the bidtime, bid, and bidder column (in that order) from the ebayBids table. | ||
\end{enumerate} | ||
|
||
\section{} | ||
In this exercise we're going to practice understanding a new database, since we may not always be the creator of the database. | ||
\begin{enumerate} | ||
\item Load the variable.db database into the DB browser. By using the schema understand what each value should look like and then insert 2 custom rows into the table. | ||
\end{enumerate} | ||
\pagebreak | ||
|
||
\section{1 Solutions} | ||
\begin{enumerate} | ||
\item | ||
\item \begin{enumerate} | ||
\item SELECT * \newline | ||
FROM ebayBids\newline | ||
LIMIT 10; | ||
\item SELECT * \newline | ||
FROM ebayAuctions\newline | ||
LIMIT 10; | ||
\end{enumerate} | ||
\item SELECT bidtime, bid, bidder \newline | ||
FROM ebayBids\newline | ||
LIMIT 10; | ||
\end{enumerate} | ||
|
||
\section{2 Solutions} | ||
\begin{enumerate} | ||
\item INSERT INTO userData VALUES (3, 3, 2, 'Share', 1314543.01), (4, 2, 2, 'Share', 1382748.57); | ||
\end{enumerate} | ||
\end{document} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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,76 @@ | ||
\documentclass[USenglish,final,authoryear,12pt]{article} | ||
|
||
|
||
|
||
\usepackage{amsmath} | ||
\usepackage[a4paper]{geometry} | ||
\geometry{ | ||
a4paper, | ||
total={210mm,297mm}, | ||
left=20mm, | ||
right=20mm, | ||
top=20mm, | ||
bottom=20mm, | ||
} | ||
|
||
\usepackage{sectsty} | ||
\usepackage{cancel} %need to use this | ||
\usepackage{babel} | ||
%\allsectionsfont{\normalfont\sffamily\bfseries} | ||
\usepackage{graphicx} | ||
\usepackage{caption} | ||
\usepackage{subcaption} | ||
\usepackage{longtable} | ||
%\begin{figure}[h] | ||
% \centering | ||
% \includegraphics[scale=0.5]{Image1.png} | ||
% \caption{Size of observable universe comparison between standard model of cosmology with inflation and without inflation [1].} | ||
%\end{figure} | ||
|
||
\begin{document} | ||
\textbf{\LARGE Exercise Sheet 2}\newline | ||
In this exercise sheet we're going to work on data filtering for easier analysis.\newline | ||
|
||
For these exercises we'll be using the userWithDate.db that you can find in the attachments. | ||
\section{Exercise 1} | ||
\begin{enumerate} | ||
\item Find all the events that user 3 has performed | ||
\item Find all the events that have an l in their name | ||
\item Find all Login and Logout events | ||
\end{enumerate} | ||
|
||
\section{Exercise 2} | ||
|
||
\begin{enumerate} | ||
\item Find all the photo events, and display them in order of most recent first | ||
\item Filter these events for just the ones that happened in the most recent 30 seconds, relative to the time of the most recent event | ||
\end{enumerate} | ||
\pagebreak | ||
|
||
\section{Exercise 1 Sample Solutions} | ||
\begin{enumerate} | ||
\item SELECT *\newline | ||
FROM userData\newline | ||
WHERE userId = 3; | ||
\item SELECT *\newline | ||
FROM userData\newline | ||
WHERE eventName LIKE '\%l\%'; | ||
\item SELECT *\newline | ||
FROM userData\newline | ||
WHERE eventName IN ('Login','Logout'); | ||
\end{enumerate} | ||
|
||
\section{Exercise 2 Sample Solutions} | ||
\begin{enumerate} | ||
\item SELECT *\newline | ||
FROM userData\newline | ||
WHERE eventName = 'Photo'\newline | ||
ORDER BY time DESC; | ||
\item SELECT *\newline | ||
FROM userData\newline | ||
WHERE eventName = 'Photo' AND\newline | ||
"time"$>=$ 1546297477.070375-30\newline | ||
ORDER BY time DESC; | ||
\end{enumerate} | ||
\end{document} | ||
|
Binary file not shown.
This file contains 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,81 @@ | ||
\documentclass[USenglish,final,authoryear,12pt]{article} | ||
|
||
|
||
|
||
\usepackage{amsmath} | ||
\usepackage[a4paper]{geometry} | ||
\geometry{ | ||
a4paper, | ||
total={210mm,297mm}, | ||
left=20mm, | ||
right=20mm, | ||
top=20mm, | ||
bottom=20mm, | ||
} | ||
|
||
\usepackage{sectsty} | ||
\usepackage{cancel} %need to use this | ||
\usepackage{babel} | ||
%\allsectionsfont{\normalfont\sffamily\bfseries} | ||
\usepackage{graphicx} | ||
\usepackage{caption} | ||
\usepackage{subcaption} | ||
\usepackage{longtable} | ||
%\begin{figure}[h] | ||
% \centering | ||
% \includegraphics[scale=0.5]{Image1.png} | ||
% \caption{Size of observable universe comparison between standard model of cosmology with inflation and without inflation [1].} | ||
%\end{figure} | ||
|
||
\begin{document} | ||
\textbf{\LARGE Exercise Sheet 3}\newline | ||
In this exercise sheet we're going to work on data preparation so that we have clean data to work with.\newline | ||
|
||
For these exercises we'll be using the Invoice table. | ||
\section{Exercise 1} | ||
|
||
\begin{enumerate} | ||
\item Find the time difference each invoice and the start of 2009. | ||
\end{enumerate} | ||
|
||
\section{Exercise 2} | ||
|
||
\begin{enumerate} | ||
\item Split up the InvoiceDate column into individual columns that contain the year, month, day, hour, minute, and second of each invoice. | ||
\item Find all the events that happened within the first 5 days of each month. | ||
\end{enumerate} | ||
|
||
\pagebreak | ||
\section{Exercise 1 Sample Solutions} | ||
\begin{enumerate} | ||
\item SELECT "InvoiceId",\newline | ||
"InvoiceDate",\newline | ||
"InvoiceDate"::TIMESTAMP - '2009-01-01 00:00:00'::TIMESTAMP AS td\newline | ||
FROM "Invoice"\newline | ||
LIMIT 5; | ||
\end{enumerate} | ||
|
||
\section{Exercise 2 Sample Solutions} | ||
\begin{enumerate} | ||
\item SELECT "InvoiceId",\newline | ||
"InvoiceDate",\newline | ||
SUBSTR("InvoiceDate"::TEXT,1,4)::INT AS year,\newline | ||
SUBSTR("InvoiceDate"::TEXT,6,2)::INT AS month,\newline | ||
SUBSTR("InvoiceDate"::TEXT,9,2)::INT AS day,\newline | ||
SUBSTR("InvoiceDate"::TEXT,12,2)::INT AS hour,\newline | ||
SUBSTR("InvoiceDate"::TEXT,15,2)::INT AS minute,\newline | ||
SUBSTR("InvoiceDate"::TEXT,18,2)::INT AS second\newline | ||
FROM "Invoice";\newline | ||
\item SELECT "InvoiceId",\newline | ||
"InvoiceDate",\newline | ||
SUBSTR("InvoiceDate"::TEXT,1,4)::INT AS year,\newline | ||
SUBSTR("InvoiceDate"::TEXT,6,2)::INT AS month,\newline | ||
SUBSTR("InvoiceDate"::TEXT,9,2)::INT AS day,\newline | ||
SUBSTR("InvoiceDate"::TEXT,12,2)::INT AS hour,\newline | ||
SUBSTR("InvoiceDate"::TEXT,15,2)::INT AS minute,\newline | ||
SUBSTR("InvoiceDate"::TEXT,18,2)::INT AS second\newline | ||
FROM "Invoice"\newline | ||
WHERE SUBSTR("InvoiceDate"::TEXT,9,2)::INT <= 5; | ||
\end{enumerate} | ||
\end{document} | ||
|
Binary file not shown.
This file contains 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,64 @@ | ||
\documentclass[USenglish,final,authoryear,12pt]{article} | ||
|
||
|
||
|
||
\usepackage{amsmath} | ||
\usepackage[a4paper]{geometry} | ||
\geometry{ | ||
a4paper, | ||
total={210mm,297mm}, | ||
left=20mm, | ||
right=20mm, | ||
top=20mm, | ||
bottom=20mm, | ||
} | ||
|
||
\usepackage{sectsty} | ||
\usepackage{cancel} %need to use this | ||
\usepackage{babel} | ||
%\allsectionsfont{\normalfont\sffamily\bfseries} | ||
\usepackage{graphicx} | ||
\usepackage{caption} | ||
\usepackage{subcaption} | ||
\usepackage{longtable} | ||
%\begin{figure}[h] | ||
% \centering | ||
% \includegraphics[scale=0.5]{Image1.png} | ||
% \caption{Size of observable universe comparison between standard model of cosmology with inflation and without inflation [1].} | ||
%\end{figure} | ||
|
||
\begin{document} | ||
\textbf{\LARGE Exercise Sheet 4}\newline | ||
\section{Exercises} | ||
\begin{enumerate} | ||
\item Using the Invoice table, find the number of invoices each customer has and filter for customers that don't have exactly 7 invoices. | ||
\item Using the InvoiceLine table, find the number of unique tracks purchased by each customer. Are there any customers who did not purchase exactly 38 tracks? | ||
\item Are there any customers who purchased a track more than once? | ||
\end{enumerate} | ||
\pagebreak | ||
|
||
\section{Sample Solutions} | ||
\begin{enumerate} | ||
\item SELECT "CustomerId",\newline | ||
COUNT(1) AS num\_invoices\newline | ||
FROM "Invoice"\newline | ||
GROUP BY "CustomerId"\newline | ||
HAVING COUNT(1) != 7; | ||
\item SELECT iv."CustomerId",\newline | ||
COUNT(DISTINCT "TrackId") AS unique\_tracks\_purchased\newline | ||
FROM "InvoiceLine" ivl\newline | ||
JOIN "Invoice" iv\newline | ||
ON ivl."InvoiceId" = iv."InvoiceId"\newline | ||
GROUP BY "CustomerId"\newline | ||
HAVING COUNT(DISTINCT "TrackId") != 38; | ||
\item SELECT iv."CustomerId", | ||
COUNT(DISTINCT "TrackId") AS unique\_tracks\_purchased, | ||
COUNT("TrackId") AS tracks\_purchased | ||
FROM "InvoiceLine" ivl | ||
JOIN "Invoice" iv | ||
ON ivl."InvoiceId" = iv."InvoiceId" | ||
GROUP BY "CustomerId" | ||
HAVING COUNT(DISTINCT "TrackId") != COUNT("TrackId"); | ||
\end{enumerate} | ||
\end{document} | ||
|
Binary file not shown.
This file contains 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,59 @@ | ||
\documentclass[USenglish,final,authoryear,12pt]{article} | ||
|
||
|
||
|
||
\usepackage{amsmath} | ||
\usepackage[a4paper]{geometry} | ||
\geometry{ | ||
a4paper, | ||
total={210mm,297mm}, | ||
left=20mm, | ||
right=20mm, | ||
top=20mm, | ||
bottom=20mm, | ||
} | ||
|
||
\usepackage{sectsty} | ||
\usepackage{cancel} %need to use this | ||
\usepackage{babel} | ||
%\allsectionsfont{\normalfont\sffamily\bfseries} | ||
\usepackage{graphicx} | ||
\usepackage{caption} | ||
\usepackage{subcaption} | ||
\usepackage{longtable} | ||
%\begin{figure}[h] | ||
% \centering | ||
% \includegraphics[scale=0.5]{Image1.png} | ||
% \caption{Size of observable universe comparison between standard model of cosmology with inflation and without inflation [1].} | ||
%\end{figure} | ||
|
||
\begin{document} | ||
\textbf{\LARGE Exercise Sheet 5}\newline | ||
\section{Exercises} | ||
\begin{enumerate} | ||
\item Using the Invoice table, find out how much people from each country spent on tracks in total. | ||
\item Using the Invoice and Invoice Line table, find the earliest date each track was purchased on. | ||
\end{enumerate} | ||
\pagebreak | ||
|
||
\section{Sample Solutions} | ||
\begin{enumerate} | ||
\item SELECT "BillingCountry",\newline | ||
SUM("Total") as total\_spent\newline | ||
FROM "Invoice"\newline | ||
GROUP BY "BillingCountry"\newline | ||
ORDER BY total\_spent DESC; | ||
\item SELECT sub."InvoiceDate",\newline | ||
sub."TrackId"\newline | ||
FROM(SELECT iv."InvoiceDate",\newline | ||
ivl."TrackId",\newline | ||
ROW\_NUMBER() OVER w as row\_num\newline | ||
FROM "InvoiceLine" ivl\newline | ||
JOIN "Invoice" iv\newline | ||
ON ivl."InvoiceId" = iv."InvoiceId"\newline | ||
WINDOW w AS (PARTITION BY ivl."TrackId" ORDER BY iv."InvoiceDate" ASC)) sub\newline | ||
WHERE sub.row\_num = 1\newline | ||
ORDER BY "TrackId" ASC; | ||
\end{enumerate} | ||
\end{document} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.