sql

合并多行表记录

1
select code,sum(nums) as counts from table group by code

将几种 group 合并为一个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
select
thecode,
sum(counts)
from
(
select
case
when code = '01' then '00'
else code
end as thecode,
counts
from
(
select
code,
sum(nums) as counts
from
table
group by
code
)
)
group by
thecode

db2