It feels like you're overcomplicating the query a little, what you want is just a year wise sum of amount
, grouped by limit
. This can be done using a CASE
;
SELECT
limit,
SUM(CASE WHEN year=2013 THEN amount ELSE 0 END) amountN,
SUM(CASE WHEN year=2014 THEN amount ELSE 0 END) amountN1
FROM myTable
GROUP BY limit
ORDER BY limit;
(if we're talking Access here, you will need to use IIF
instead of CASE
)