add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE company (id int, year int, dept varchar(10), amt int);
INSERT INTO company VALUES
(1, 2022, 'A', 100),
(1, 2022, 'B', 100),
(1, 2023, 'A', 100),
(1, 2023, 'B', 100),
(1, 2022, 'C', 125),
(1, 2023, 'C', 150),

(2, 2022, 'A', 100),
(2, 2022, 'B', 100),
(2, 2023, 'A', 100),
(2, 2023, 'B', 100),
(2, 2022, 'C', 155),
(2, 2023, 'C', 135);

select * from company;
Records: 12  Duplicates: 0  Warnings: 0
id year dept amt
1 2022 A 100
1 2022 B 100
1 2023 A 100
1 2023 B 100
1 2022 C 125
1 2023 C 150
2 2022 A 100
2 2022 B 100
2 2023 A 100
2 2023 B 100
2 2022 C 155
2 2023 C 135
select id, year, sum(amt)
from company
Where dept not in ('B')
group by id, year
id year sum(amt)
1 2022 225
1 2023 250
2 2022 255
2 2023 235