Skip to content
Advertisement

Self joining columns from the same table with calculation on one column not displaying column name

I am fairly new to SQL and having issues figuring out how to solve the simple issue below. I have a dataset I am trying to self-join, I am using (b.calendar_year_number -1) as one of the columns to join. I applied a calculation of -1 with the goal of trying to match values from the previous year. However, it is not working as the resulting column shows (No column name) with a screenshot attached below. How do I change the alias to b.calendar_year_number after the calculation?

Code:

enter image description here

Advertisement

Answer

I am using (b.calendar_year_number -1) as one of the columns to join.

Nope, you’re not. Look at your join statement and you’ll see the third condition is:

So just change that to include the calculation. As far as the ‘no column name’ issue, you can use colname = somelogic syntax or somelogic as colname. Below, I used the former syntax.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement