Skip to content

Instantly share code, notes, and snippets.

@moqdm
Created September 7, 2021 19:27
Show Gist options
  • Save moqdm/c36ceca39776eeb1c7fe00b27b3e1242 to your computer and use it in GitHub Desktop.
Save moqdm/c36ceca39776eeb1c7fe00b27b3e1242 to your computer and use it in GitHub Desktop.
it's my PSet 7: Fiftyville solution... *Please just take a look if you couldn't solve it ... Thank you πŸ™‚ #cs50
-- Keep a log of any SQL queries you execute as you solve the mystery.
-- Get descriptions of the crimes that happened in 28-July(7)-2020 in the Chamberlin St.
SELECT description FROM crime_scene_reports WHERE day = "28" AND month = "7" AND year = "2020" AND street = "Chamberlin Street";
-- Check the transcript of the theft date interviews mentioned by the courthouse.
SELECT transcript FROM interviews WHERE day = "28" AND month = "7" AND year = "2020" AND transcript like "%courthouse%";
-- Based on transcript of the first interview: Finding the names of the people who exit the courthouse 10 minutes after the theft.
SELECT name FROM people JOIN courthouse_security_logs ON people.license_plate = courthouse_security_logs.license_plate WHERE day = "28" AND month = "7" AND year = "2020" AND hour = "10" AND minute >= "15" AND minute < "25" AND activity = "exit";
-- Based on transcript of the second interview: Finding the names of the people who withdrew money from the ATM on Fifer St on the day of the theft.
SELECT DISTINCT name FROM people JOIN bank_accounts ON people.id = bank_accounts.person_id JOIN atm_transactions ON bank_accounts.account_number = atm_transactions.account_number WHERE day = "28" AND month = "7" AND year = "2020" AND transaction_type = "withdraw" AND atm_location = "Fifer Street";
-- Based on the transcript of the third interview: Finding the names of the people who bought the first flight ticket for the day after the theft.
SELECT name FROM people JOIN passengers ON people.passport_number = passengers.passport_number WHERE flight_id = (SELECT id FROM flights WHERE day = "29" AND month = "7" AND year = "2020" ORDER BY hour,minute LIMIT 1);
-- Based on the transcript of the third interview: Finding the names of the people who had call for less than a minute on the day of the theft.
SELECT name FROM people JOIN phone_calls ON people.phone_number = phone_calls.caller WHERE day = "28" AND month = "7" AND year = "2020" AND duration < "60";
-- Meet all the conditions to find the thief.
SELECT name FROM people JOIN passengers ON people.passport_number = passengers.passport_number WHERE flight_id = (SELECT id FROM flights WHERE day = "29" AND month = "7" AND year = "2020" ORDER By hour, minute LIMIT 1) INTERSECT SELECT DISTINCT name FROM people JOIN bank_accounts ON people.id = bank_accounts.person_id JOIN atm_transactions ON bank_accounts.account_number = atm_transactions.account_number WHERE day = "28" AND month = "7" AND year = "2020" AND transaction_type = "withdraw" AND atm_location = "Fifer Street" INTERSECT SELECT name FROM people JOIN phone_calls ON people.phone_number = phone_calls.caller WHERE day = "28" AND month = "7" AND year = "2020" AND duration < "60" INTERSECT SELECT name FROM people JOIN courthouse_security_logs ON people.license_plate = courthouse_security_logs.license_plate WHERE day = "28" AND month = "7" AND year = "2020" AND hour = "10" AND minute >= "15" AND minute < "25" AND activity = "exit";
-- Based on the transcript of the third interview: Finding the destination of the first flight ticket for the day after the theft.
SELECT city FROM airports WHERE id = (SELECT destination_airport_id FROM flights WHERE day = "29" AND month = "7" AND year = "2020" ORDER BY hour,minute LIMIT 1);
-- Based on the transcript of the third interview: Finding the name of the person whom the thief had call for less than a minute on the day of the theft.
SELECT name FROM people JOIN phone_calls ON people.phone_number = phone_calls.receiver WHERE day = "28" AND month = "7" AND year = "2020" AND duration < "60" AND caller = (SELECT phone_number FROM people WHERE name = "Ernest");
-- The thief is Ernest, He ESCAPED TO London with Berthold help.
@itss-moner
Copy link

Actually the thief is Bruce who escaped to New York City and his accomplice was Robin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment