-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathchapter4_solutions.html
77 lines (57 loc) · 1.85 KB
/
chapter4_solutions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!doctype html>
<html>
<head>
<title>Solutions - Who was the string puller?</title>
<link rel=stylesheet href="http://fonts.googleapis.com/css?family=Averia+Serif+Libre:300,400">
<link rel=stylesheet href=style.css>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
</head>
<body>
<h1>Solutions - Who was the string puller?</h1>
<ol start="29">
<li><p class=answer>The tables <code>account</code> and <code>bank_transaction</code></p>
</li>
<li><p class=answer>Via foreign key on <code>bank_transaction</code> referencing the table <code>account</code>, both have a primary key and connection to table name via the column <code>name</code> <em>without foreign constraint</em>.</p>
</li>
<li><p class=answer>Via the column <code>name</code> in the tables <code>person</code> and <code>account</code>.</p></li>
<li><p class=answer>203993 and 203987</p>
</li>
<li><p class=answer>Use</p>
<pre>
select * from account where name
like 'Sara%' or name like 'Philip%';
</pre></li>
<li><p class=answer>Use</p>
<pre>
select sum(amount) from bank_transaction
where account_number_fk = 203987;
</pre>
<p class=answer>and</p>
<pre>
select sum(amount) from bank_transaction
where account_number_fk = (select account_number_pk
from account where name like 'Sara%');
</pre></li>
<li><p class=answer>Use</p>
<pre>
select sum(amount) from bank_transaction
where account_number_fk = 203987
and date > "2014-10-22" and date < "2014-10-26";
</pre></li>
<li><p class=answer>Use</p>
<pre>
select account_number_fk, sum(amount)
from bank_transaction where date > "2014-10-22";
</pre>
<p class=answer>and</p>
<pre>
select account_number_fk, sum(amount)
from bank_transaction where date > "2014-10-22"
and date < "2014-10-26"
group by account_number_fk having sum(amount) > 10000;
</pre>
</li>
</ol>
<p><a href="chapter4.html">Back to Tutorial</a></p>
</body>
</html>