mpope9 / nba-sql

:basketball: An application to build an NBA database backed by MySQL, Postgres, or SQLite
Apache License 2.0
171 stars 20 forks source link

Question: Is my query right? #84

Closed sscrewston closed 1 year ago

sscrewston commented 1 year ago

I'm still fairly new to SQL, I used this query

SELECT
    DISTINCT shot_chart_detail.id,
    strftime('%m-%d-%Y') AS game_date,
    game.game_id,
    player_name,
    shot_type,
    event_type,
    action_type,
    period AS quarter,
    minutes_remaining,
    seconds_remaining
FROM game
    INNER JOIN shot_chart_detail
    ON game.game_id = shot_chart_detail.game_id
    INNER JOIN player
    ON shot_chart_detail.player_id = player.player_id
WHERE team_id = 1610612745
ORDER BY game_date DESC

However, when I retrieve that game_date column I see dates from one day ahead, games that haven't even happened yet. What am I doing wrong?

Untitled
mpope9 commented 1 year ago

Try selecting game.game_date instead of strftime.

sscrewston commented 1 year ago

game_date was the alias I gave the strftime. I used strftime to extract the date value only from the date column because by default it is a string value in YYYY-MM-DDT00:00:00 format. In default format I can't sort the date properly so I'm trying to figure out a solution with my limited knowledge of SQL.

Screenshot 2022-11-18 at 7 40 33 AM
mpope9 commented 1 year ago

I think strftime returns the current date. You might want game.game_date, if you want a game's date.

mpope9 commented 1 year ago

Or maybe pass it to strftime. Like

strftime(format, game.game_date)
sscrewston commented 1 year ago

Okay, thank you. I’ll try that when I get a chance.

On Fri, Nov 18, 2022 at 8:13 AM Matthew Pope @.***> wrote:

Or maybe pass it to strftime. Like

strftime(format, game.game_date)

— Reply to this email directly, view it on GitHub https://github.com/mpope9/nba-sql/issues/84#issuecomment-1320046500, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZFVOKBBVGHPY2NEQZMNGT3WI6FG5ANCNFSM6AAAAAASED3PGI . You are receiving this because you authored the thread.Message ID: @.***>