This view includes information about energy usage by City facilities for current and previous year (same month, prior year) Also included are calculated targets for reductions in energy consumption and progress toward achieving them (% change).
SELECT
`row_id`,
`site`,
`site_type`,
`category`,
`address`,
`latitude`,
`longitude`,
`geolocation`,
`premise_code_account_number`,
`building_flag`,
`ems_flag`,
`square_footage`,
`month_date`,
@self.`month_date` AS `previous_date`,
`year`,
`month`,
`kwh`,
@self.`kwh` AS `previous_kwh_usage`,
@self.`kwh` * 0.95 AS `target_kwh`,
case(`target_kwh` > 0, (`kwh` - `target_kwh`) / `target_kwh`) AS `target_percent_change`,
case(`target_kwh` > 0, (`kwh` - `previous_kwh_usage`) / `previous_kwh_usage`) AS `percent_change`
LEFT OUTER JOIN @ksen-g4gs AS @self ON ((date_diff_d(`month_date`, @self.`month_date`)= 365)
OR (date_diff_d(`month_date`, @self.`month_date`) = 366))
AND (`premise_code_account_number` == @self.`premise_code_account_number`)
ORDER BY month_date desc