0
I have the following select command:
SELECT
pa_coduni,
pa_proc_id,
sum(case when substr(pa_cmp, 1, 4) = 2017 then pa_qtdapr else 0 end) a2017,
sum(case when substr(pa_cmp, 1, 4) = 2018 then pa_qtdapr else 0 end) a2018,
sum(pa_qtdapr) total
FROM
bacabalma
where
substr(pa_cmp, 1, 4) >= 2017
group by
pa_coduni, substr(pa_cmp, 1, 4), pa_proc_id
order by
pa_coduni, pa_proc_id
It works well, but the result comes out like this:
pa_coduni | pa_proc_id | a2017 | a2018 | total
aaa |aaaa | 1 | 0 | 1
aaa |aaaa | 0 | 1 | 1
How to make the result come like this:
pa_coduni | pa_proc_id | a2017 | a2018 | total
aaa |aaaa | 1 | 1 | 2