Advertisement
CodaarX

Database

Feb 2nd, 2021
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 12.95 KB | None | 0 0
  1. -- Keep a log of any SQL queries you execute as you solve the mystery.
  2.  
  3. -- Extract all information about the exact crime scene of interest
  4. SELECT * FROM crime_scene_reports WHERE DAY = 28 AND street = "Chamberlin Street";
  5. -- RESULT
  6. -- id | year | month | day | street | description
  7. -- 295 | 2020 | 7 | 28 | Chamberlin Street |
  8. -- Theft of the CS50 duck took place at 10:15am at the Chamberlin Street courthouse.
  9. -- Interviews were conducted today with three witnesses who were present at the time each of their interview transcripts mentions the courthouse.
  10.  
  11. -- get information about interviews held at 10: 15 am
  12. SELECT * FROM interviews WHERE DAY = 28 AND MONTH = 7 AND YEAR = 2020 ORDER BY (name);
  13. -- RESULT
  14. -- id  | name | year | month | day | transcript
  15. -- 162 | Eugene | 2020 | 7 | 28 | I don't know the thief's name, but it was someone I recognized. Earlier this morning, before I arrived at the courthouse, I was walking by the ATM on Fifer Street and saw the thief there withdrawing some money.
  16. -- 163 | Raymond | 2020 | 7 | 28 | As the thief was leaving the courthouse, 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.
  17. -- 161 | Ruth | 2020 | 7 | 28 | Sometime within ten minutes of the theft, I saw the thief get into a car in the courthouse parking lot and drive away. If you have security footage from the courthouse parking lot, you might want to look for cars that left the parking lot in that time frame.
  18.  
  19. -- get Engene's trail to lead anyone who withdrew on Fifer street
  20. SELECT * FROM atm_transactions
  21. WHERE atm_location = "Fifer Street" AND DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND transaction_type = "withdraw";
  22. -- id | account_number | year | month | day | atm_location | transaction_type | amount
  23. -- 246 | 28500762 | 2020 | 7 | 28 | Fifer Street | withdraw | 48
  24. -- 264 | 28296815 | 2020 | 7 | 28 | Fifer Street | withdraw | 20
  25. -- 266 | 76054385 | 2020 | 7 | 28 | Fifer Street | withdraw | 60
  26. -- 267 | 49610011 | 2020 | 7 | 28 | Fifer Street | withdraw | 50
  27. -- 269 | 16153065 | 2020 | 7 | 28 | Fifer Street | withdraw | 80
  28. -- 288 | 25506511 | 2020 | 7 | 28 | Fifer Street | withdraw | 20
  29. -- 313 | 81061156 | 2020 | 7 | 28 | Fifer Street | withdraw | 30
  30. -- 336 | 26013199 | 2020 | 7 | 28 | Fifer Street | withdraw | 35
  31.  
  32. -- get Raymond's trail to get calls less than a minute on the said day
  33. SELECT * FROM phone_calls WHERE  DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND duration < 60;
  34. -- id | caller | receiver | year | month | day | duration
  35. -- 221 | (130) 555-0289 | (996) 555-8899 | 2020 | 7 | 28 | 51
  36. -- 224 | (499) 555-9472 | (892) 555-8872 | 2020 | 7 | 28 | 36
  37. -- 233 | (367) 555-5533 | (375) 555-8161 | 2020 | 7 | 28 | 45
  38. -- 251 | (499) 555-9472 | (717) 555-1342 | 2020 | 7 | 28 | 50
  39. -- 254 | (286) 555-6063 | (676) 555-6554 | 2020 | 7 | 28 | 43
  40. -- 255 | (770) 555-1861 | (725) 555-3243 | 2020 | 7 | 28 | 49
  41. -- 261 | (031) 555-6622 | (910) 555-3251 | 2020 | 7 | 28 | 38
  42. -- 279 | (826) 555-1652 | (066) 555-9701 | 2020 | 7 | 28 | 55
  43. -- 281 | (338) 555-6650 | (704) 555-2131 | 2020 | 7 | 28 | 54
  44.  
  45. -- Get Ruth's trail to identify who left the parking lot within 10 minutes of the theft
  46. SELECT * FROM courthouse_security_logs
  47. WHERE DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND HOUR = 10 AND activity = "exit" AND (MINUTE > 15 AND MINUTE < 25);
  48. -- id | year | month | day | hour | minute | activity | license_plate
  49. -- 260 | 2020 | 7 | 28 | 10 | 16 | exit | 5P2BI95
  50. -- 261 | 2020 | 7 | 28 | 10 | 18 | exit | 94KL13X
  51. -- 262 | 2020 | 7 | 28 | 10 | 18 | exit | 6P58WS2
  52. -- 263 | 2020 | 7 | 28 | 10 | 19 | exit | 4328GD8
  53. -- 264 | 2020 | 7 | 28 | 10 | 20 | exit | G412CB7
  54. -- 265 | 2020 | 7 | 28 | 10 | 21 | exit | L93JTIZ
  55. -- 266 | 2020 | 7 | 28 | 10 | 23 | exit | 322W7JE
  56. -- 267 | 2020 | 7 | 28 | 10 | 23 | exit | 0NTHK55
  57.  
  58. -- GET the names of all airport flight the day after the theft
  59. SELECT airports.id, abbreviation, full_name, destination_airport_id, city, HOUR, MINUTE FROM airports
  60. JOIN flights ON flights.destination_airport_id = airports.id
  61. WHERE origin_airport_id = 8 AND DAY = 29 AND MONTH = 7 AND YEAR = 2020;
  62. -- id | abbreviation | full_name | destination_airport_id | city | hour | minute
  63. -- 6 | BOS | Logan International Airport | 6 | Boston | 16 | 0
  64. -- 11 | SFO | San Francisco International Airport | 11 | San Francisco | 12 | 15
  65. -- 4 | LHR | Heathrow Airport | 4 | London | 8 | 20
  66. -- 1 | ORD | O'Hare International Airport | 1 | Chicago | 9 | 30
  67. -- 9 | HND | Tokyo International Airport | 9 | Tokyo | 15 | 20
  68.  
  69. -- get all airport flights with origin being fiftyville (flight will be the following day - 29th july)
  70. SELECT * FROM flights WHERE DAY = 29 AND MONTH = 7 AND YEAR = 2020;
  71. -- id | origin_airport_id | destination_airport_id | year | month | day | hour | minute
  72. -- 18 | 8 | 6 | 2020 | 7 | 29 | 16 | 0
  73. -- 23 | 8 | 11 | 2020 | 7 | 29 | 12 | 15
  74. -- 36 | 8 | 4 | 2020 | 7 | 29 | 8 | 20
  75. -- 43 | 8 | 1 | 2020 | 7 | 29 | 9 | 30
  76. -- 53 | 8 | 9 | 2020 | 7 | 29 | 15 | 20
  77.  
  78. --- get all passengers in the earliest flight of the day
  79. SELECT people.name, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  80. JOIN passengers ON passengers.passport_number = people.passport_number
  81. WHERE flight_id = 36;
  82. -- name | id | license_plate | phone_number | passport_number
  83. -- Doris | 953679 | M51FA04 | (066) 555-9701 | 7214083635
  84. -- Roger | 398010 | G412CB7 | (130) 555-0289 | 1695452385
  85. -- Ernest | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  86. -- Edward | 651714 | 130LD9Z | (328) 555-1152 | 1540955065
  87. -- Evelyn | 560886 | 0NTHK55 | (499) 555-9472 | 8294398571
  88. -- Madison | 449774 | 1106N58 | (286) 555-6063 | 1988161715
  89. -- Bobby | 395717 | 30G67EN | (826) 555-1652 | 9878712108
  90. -- Danielle | 467400 | 4328GD8 | (389) 555-5198 | 8496433585
  91.  
  92.  
  93. -- get names and id of everyone who exited the parking lot within 10 minutesof the crime
  94. SELECT people.name, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  95. JOIN courthouse_security_logs ON courthouse_security_logs.license_plate = people.license_plate
  96. WHERE DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND HOUR = 10 AND activity = "exit" AND MINUTE  < 25;
  97. -- name | id | license_plate | phone_number | passport_number
  98. -- Patrick | 221103 | 5P2BI95 | (725) 555-4692 | 2963008352
  99. -- Amber | 243696 | 6P58WS2 | (301) 555-4174 | 7526138472
  100. -- Elizabeth | 396669 | L93JTIZ | (829) 555-5269 | 7049073643
  101. -- Roger | 398010 | G412CB7 | (130) 555-0289 | 1695452385
  102. -- Danielle | 467400 | 4328GD8 | (389) 555-5198 | 8496433585
  103. -- Russell | 514354 | 322W7JE | (770) 555-1861 | 3592750733
  104. -- Evelyn | 560886 | 0NTHK55 | (499) 555-9472 | 8294398571
  105. -- Ernest | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  106.  
  107. -- selects the name and bank account of everyone who exited the premises on the said day
  108. SELECT people.name, account_number, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  109. JOIN bank_accounts ON bank_accounts.person_id = people.id
  110. JOIN passengers ON passengers.passport_number = people.passport_number
  111. JOIN courthouse_security_logs ON courthouse_security_logs.license_plate = people.license_plate
  112. WHERE DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND HOUR = 10 AND activity = "exit" AND MINUTE  < 25 AND flight_id = 4;
  113.  
  114. -- name | account_number | id | license_plate | phone_number | passport_number
  115. -- Ernest | 49610011 | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  116. -- Russell | 26013199 | 514354 | 322W7JE | (770) 555-1861 | 3592750733
  117. -- Elizabeth | 25506511 | 396669 | L93JTIZ | (829) 555-5269 | 7049073643
  118. -- Danielle | 28500762 | 467400 | 4328GD8 | (389) 555-5198 | 8496433585
  119. -- Amber | 56171033 | 243696 | 6P58WS2 | (301) 555-4174 | 7526138472
  120.  
  121. -- tag the passport number to the suspect
  122. SELECT people.name, account_number, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  123. JOIN bank_accounts ON bank_accounts.person_id = people.id
  124. JOIN passengers ON passengers.passport_number = people.passport_number
  125. JOIN courthouse_security_logs ON courthouse_security_logs.license_plate = people.license_plate
  126. WHERE DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND HOUR = 10 AND activity = "exit" AND MINUTE  < 25
  127. GROUP BY people.name;
  128. -- name | account_number | id | license_plate | phone_number | passport_number
  129. -- Danielle | 28500762 | 467400 | 4328GD8 | (389) 555-5198 | 8496433585
  130. -- Elizabeth | 25506511 | 396669 | L93JTIZ | (829) 555-5269 | 7049073643
  131. -- Ernest | 49610011 | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  132. -- Russell | 26013199 | 514354 | 322W7JE | (770) 555-1861 | 3592750733
  133.  
  134. -- Link bank account, is, hone number, licence plates of everyone to see who matches the query of the said day
  135.  
  136. SELECT people.name, bank_accounts.account_number, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  137. JOIN bank_accounts ON bank_accounts.person_id = people.id
  138. JOIN atm_transactions ON atm_transactions.account_number = bank_accounts.account_number
  139. JOIN phone_calls ON phone_calls.caller = people.phone_number
  140. JOIN passengers ON passengers.passport_number = people.passport_number
  141. JOIN courthouse_security_logs ON courthouse_security_logs.license_plate = people.license_plate
  142. WHERE courthouse_security_logs.DAY = 28 AND courthouse_security_logs.MONTH = 7 AND courthouse_security_logs.YEAR = 2020
  143. AND courthouse_security_logs.HOUR = 10 AND courthouse_security_logs.activity = "exit"
  144. AND courthouse_security_logs.MINUTE  < 25 AND atm_location = "Fifer Street" AND transaction_type = "withdraw"
  145. GROUP BY people.name;
  146.  
  147. -- name | account_number | id | license_plate | phone_number | passport_number
  148. -- Danielle | 28500762 | 467400 | 4328GD8 | (389) 555-5198 | 8496433585
  149. -- Elizabeth | 25506511 | 396669 | L93JTIZ | (829) 555-5269 | 7049073643
  150. -- Ernest | 49610011 | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  151. -- Russell | 26013199 | 514354 | 322W7JE | (770) 555-1861 | 3592750733
  152.  
  153. -- Use phone calls to filter out suspects
  154. SELECT people.name, bank_accounts.account_number, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  155. JOIN bank_accounts ON bank_accounts.person_id = people.id
  156. JOIN atm_transactions ON atm_transactions.account_number = bank_accounts.account_number
  157. JOIN phone_calls ON phone_calls.caller = people.phone_number
  158. JOIN passengers ON passengers.passport_number = people.passport_number
  159. JOIN flights ON flights.id = passengers.flight_id
  160. JOIN courthouse_security_logs ON courthouse_security_logs.license_plate = people.license_plate
  161. WHERE courthouse_security_logs.DAY = 28 AND courthouse_security_logs.MONTH = 7
  162. AND courthouse_security_logs.YEAR = 2020 AND courthouse_security_logs.HOUR = 10
  163. AND courthouse_security_logs.activity = "exit" AND courthouse_security_logs.MINUTE < 25
  164. AND atm_location = "Fifer Street" AND phone_calls.duration < 60 AND flights.DAY = 29
  165. AND flights.MONTH = 7 AND flights.YEAR = 2020 AND transaction_type = "withdraw"
  166. GROUP BY people.name;
  167.  
  168. -- name | account_number | id | license_plate | phone_number | passport_number
  169. -- Ernest | 49610011 | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  170. -- Russell | 26013199 | 514354 | 322W7JE | (770) 555-1861 | 3592750733
  171.  
  172. -- use the earliest flight to filter the culprit (Raymond said they were planning to take the earliest flight)
  173. -- Who was the thief?
  174. SELECT people.name, bank_accounts.account_number, people.id, people.license_plate, people.phone_number, people.passport_number FROM people
  175. JOIN bank_accounts ON bank_accounts.person_id = people.id
  176. JOIN atm_transactions ON atm_transactions.account_number = bank_accounts.account_number
  177. JOIN phone_calls ON phone_calls.caller = people.phone_number
  178. JOIN passengers ON passengers.passport_number = people.passport_number
  179. JOIN flights ON flights.id = passengers.flight_id
  180. JOIN courthouse_security_logs ON courthouse_security_logs.license_plate = people.license_plate
  181. WHERE courthouse_security_logs.DAY = 28 AND courthouse_security_logs.MONTH = 7
  182. AND courthouse_security_logs.YEAR = 2020 AND courthouse_security_logs.HOUR = 10
  183. AND courthouse_security_logs.activity = "exit" AND courthouse_security_logs.MINUTE < 25
  184. AND atm_location = "Fifer Street" AND phone_calls.duration < 60 AND flights.DAY = 29
  185. AND flights.MONTH = 7 AND flights.YEAR = 2020 AND transaction_type = "withdraw"
  186. AND flights.id = 36
  187. GROUP BY people.name;
  188.  
  189. -- Ernest | 49610011 | 686048 | 94KL13X | (367) 555-5533 | 5773159633
  190.  
  191.  
  192. -- Who did Ernest call?
  193. SELECT * FROM phone_calls WHERE phone_calls.caller = "(367) 555-5533" AND DAY = 28 AND MONTH = 7 AND YEAR = 2020 AND duration < 60;
  194. -- id | caller | receiver | year | month | day | duration
  195. -- 233 | (367) 555-5533 | (375) 555-8161 | 2020 | 7 | 28 | 45
  196.  
  197. -- get the name of the accomplist
  198. SELECT * FROM people WHERE people.phone_number = "(375) 555-8161";
  199. -- id | name | phone_number | passport_number | license_plate
  200. -- 864400 | Berthold | (375) 555-8161 |  | 4V16VO0
  201.  
  202. -- Berthold was his accomplice.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement