Have you tried a group by?
SELECT
year,
SUM(charge) charge
FROM
your_table
GROUP BY
year
ORDER BY
year;
The structure of the table is not really good, for example the year data is missing.
But you can run the following SQL statement which uses union all:
select '2014' as year,
sum(charge)
from your_table
where id in (123, 142)
union all
select '2015' as year,
sum(charge)
from your_table
where id in (523, 124);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.