5 ms·
SQL Murder Mystery
- gorkish 5y agoKobayashi Maru Difficulty: Discover and solve both puzzles in two queries.
- saithir 5y agoYou can't though, can you? You need at least 3 for the first one - 1 to get the info on the murder which is just text, 2nd to get the interviews (which aren't connected to the murder info, though they probably should), and then you can get to the solution in one big query.
- olsgaarddk 5y agoYou really need 3 for the first puzzle and 1 for the second puzzle. Spoilers ahead: - 1st query to get the crime report. This contain plaintext clues. - 2nd query to get witness interviews. Again, these contain plaintext clues that can't be used in a `join` statement or a `where` statement in SQL. - 3rd query to get interview with suspect. This contain plaintext information needed for solving the second puzzle - 4th query for finding the master mind. Short of writing regexes that basically extracts the clues by looking for patterns that are verbatim the clues themselves, I don't see how it can be done any shorter than this. You can see my solution here on my github: https://github.com/olsgaard/sql_murder_mystery_solution/blob/main/sql_murder_mystery.ipynb https://github.com/olsgaard/sql_murder_mystery_solution/blob...
- olsgaarddk 5y agoI took a hint from Gorkish, having never heard of SQL triggers before, and I gotta say, the 2-query answer is really thinking out of the box and very clever. I learned a lot from it!
- rkagerer 5y agoPrevious thread from 2019: https://news.ycombinator.com/item?id=21799988 https://news.ycombinator.com/item?id=21799988
- dunefox 5y agoI don't know much about databases but shouldn't where num1 <= date <= num2 throw an error if it's not supported, yet silently returns false data? The dates are integers. select * from facebook_event_checkin fb where 20171201 <= fb.date <= 20171231: 28508 | 5880 | Nudists are people who wear one-button suits. | 20170913 <--
- kevincox 5y agoI would assume that it is treated as (num1 <= date) <= num2. So (num1 < date) is true (1) or false (0) which is then (probably) less than date.
- tqi 5y agoYeah that seems to be what is happening: SELECT 20171201 <= fb.date <= 0, COUNT(1), MIN(fb.date), MAX(fb.date) FROM facebook_event_checkin fb GROUP BY 1 returns: 0 6302 20171201 20180501 1 13709 20170101 20171130 . SQLite has some completely bonkers unexpected behaviors. The above query with the "GROUP BY 1" line removed returns: 0 20011 20170101 20180501 instead of throwing an error, which is an absolutely bonkers decision.
- dunefox 5y agoPostgres seems to signal an error, which is preferable IMHO.
- dunefox 5y agoBut since 2017* is smaller than even the leftmost date it's still false, isn't it?