the differnece between to values in sql

Solutions on MaxInterview for the differnece between to values in sql by the best coders in the world

showing results for - "the differnece between to values in sql"
Diego Alejandro
20 Apr 2017
1SELECT 	
2city,
3	year,
4      population_needing_house,
5      LAG(population_needing_house)
6      OVER (PARTITION BY city ORDER BY year ) AS previous_year
7      population_needing_house - LAG(population_needing_house)
8 	OVER (PARTITION BY city ORDER BY year ) AS difference_previous_year
9FROM 	housing
10ORDER BY city, year
11