-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.sql
151 lines (129 loc) · 4.04 KB
/
log.sql
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- Keep a log of any SQL queries you execute as you solve the mystery.
SELECT year, month, day, description
FROM crime_scene_reports
WHERE month = 7 AND day = 28
AND street = 'Humphrey Street'
AND description LIKE '%CS50%';
-- Theft of the CS50 duck took place at 10:15am at the Humphrey Street bakery.
-- Interviews were conducted today with three witnesses
-- who were present at the time – each of their interview transcripts mentions the bakery.
SELECT year, month, day, transcript
FROM interviews
WHERE month = 7 AND day = 28
AND transcript LIKE '%thief%';
"
Sometime within ten minutes of the theft,
I saw the thief get into a car in the bakery parking lot and drive away.
If you have security footage from the bakery parking lot,
you might want to look for cars that left the parking lot in that time frame.
"
"
I don't know the thief's name, but it was someone I recognized.
Earlier this morning, before I arrived at Emma's bakery,
I was walking by the ATM on Leggett Street and
saw the thief there withdrawing some money.
"
"
As the thief was leaving the bakery,
they called someone who talked to them for less than a minute.
In the call, I heard the thief say that they were planning
to take the earliest flight out of Fiftyville tomorrow.
The thief then asked the person on the other end of the phone
to purchase the flight ticket.
"
SELECT flights.id, year, month, day, hour, minute, city
FROM flights
JOIN airports on airports.id = flights.destination_airport_id
JOIN passengers on passengers.flight_id = flights.id
WHERE month = 7 AND day = 29
ORDER BY hour, minute
LIMIT 1;
-- NYC
"
Trying to find persons in people table, needs 4 pieces of info:
passport
license plate
phone number
id
"
-- passport
SELECT flights.id, passport_number
FROM passengers
JOIN flights on passengers.flight_id = flights.id
WHERE flights.id IN
(SELECT flights.id
FROM flights
JOIN airports on airports.id = flights.destination_airport_id
JOIN passengers on passengers.flight_id = flights.id
WHERE month = 7 AND day = 29
ORDER BY hour, minute
LIMIT 1);
-- license plates
SELECT year, month, day, hour, minute, activity, license_plate
FROM bakery_security_logs
WHERE month = 7 AND day = 28
AND hour = 10
AND minute BETWEEN 15 AND 25
AND activity = 'exit';
-- phone numbers (caller: Bruce, receiver: Robin)
SELECT year, month, day, duration, name, receiver
FROM phone_calls
JOIN people ON people.phone_number = phone_calls.caller
WHERE month = 7 AND day = 28
AND duration <= 60;
-- id
SELECT person_id
FROM bank_accounts
WHERE account_number IN
(SELECT account_number
FROM atm_transactions
WHERE month = 7 AND day = 28
AND atm_location = 'Leggett Street'
AND transaction_type = 'withdraw');
-- =======================SUSPECT LIST=============================== --
SELECT id, name
FROM people
-- passport
WHERE passport_number IN
(SELECT passport_number
FROM passengers
JOIN flights on passengers.flight_id = flights.id
WHERE flights.id IN
(SELECT flights.id
FROM flights
JOIN airports on airports.id = flights.destination_airport_id
JOIN passengers on passengers.flight_id = flights.id
WHERE month = 7 AND day = 29
ORDER BY hour, minute
LIMIT 1)
)
-- license plate
AND license_plate IN
(SELECT license_plate
FROM bakery_security_logs
WHERE month = 7 AND day = 28
AND hour = 10
AND minute BETWEEN 15 AND 25 -- important key: within 10 minutes after 10:15AM
AND activity = 'exit')
-- phone number
AND phone_number IN
(SELECT caller
FROM phone_calls
WHERE month = 7 AND day = 28
AND duration <= 60)
-- id
AND id IN
(SELECT person_id
FROM bank_accounts
WHERE account_number IN
(SELECT account_number
FROM atm_transactions
WHERE month = 7 AND day = 28
AND atm_location = 'Leggett Street'
AND transaction_type = 'withdraw')
);
"
| Bruce |
"
-- go back to phone_calls and check entries where caller = Bruce. Only 1 entry presented.
-- find accomplice, which is the receiver of the phone call