mpope9/nba-sql

Question: Is my query right?

sscrewston opened this issue · 5 comments

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

Try selecting game.game_date instead of strftime.

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

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

Or maybe pass it to strftime. Like

strftime(format, game.game_date)