For the following subquery:
;WITH results as (
SELECT 'DAL' as team, 2010 as season, 7 as wins union
SELECT 'DAL' as team, 2011 as season, 11 as wins union
SELECT 'DAL' as team, 2012 as season, 11 as wins union
SELECT 'NE' as team, 2012 as season, 15 as wins union
SELECT 'DET' as team, 2010 as season, 6 as wins
)
SELECT team, wins, season,
wins - (select max(wins) from results as r where r.season=results.season) difference_from_best_subquery
FROM results;
What is the proper way to alias the results so its clear that you want to pass "this" value into the results? The above works, but I'd hope that I could do something a bit more readable (to myself) such as:
SELET MAX(wins) FROM table WHERE wins=$this.wins
What's the best approach to this?