Search code examples
sqldomo

Select last full column in SQL


I'm new to SQL, so forgive me if this is silly.

I have a bunch of different rows, each a new match in a game. The columns are defined by minutes. So min_1, is the start of the first minute, min_2 is the start of the second and so on. Each row shows the amount of gold a team has at that time, so for min_1 its 0, min_9 its 9012, min_12 its 14587 etc.

Now I need to find the total gold they had, which in a 12 minute game, would be 14587 in this case. However, not every game is 12 minutes. Some might be 12, some might be 24, most are between 40-50 minutes. After the game ends, the values in my table and just empty. So for this 12 minute game, min_13 is just blank (the original file is a csv, its in table form so its value will be null).

So is there a way in SQL to look on a row, find the last non-empty column, and report the value?

So far my code would be:

CASE
  WHEN `blueTeamTag`= 'FNC'
  AND `Type` = 'goldblue'
  THEN <This is where it would select the column>
END

Solution

  • Are you coding in a language? If you’re using python you could query each column until you hit a column that contains values.

    I use SQL regularly professionally and I can’t think of a way to do this with just SQL.