The join
should be fine if you add indexes to IMP_TOT_YEAR
:
create index IMP_TOT_YEAR_az_yr on IMP_TOT_YEAR(az, yr);
It sounds like you have a lot of data, so using an intermediate table might be fast.
On the other hand, if you want to do it in one table, be sure you have an index on IMP_TOT(az, yr)
and try:
SELECT t.*,
(SELECT SUM(imp) as imp.year,
FROM IMP_TOT t2
WHERE t2.az = t.az and t2.yr = t.yr
) as YearTot
FROM IMP_TOT;