我有这样的数据:
ID NR TYPE
-------------- -------------- ---------------
01 44 A
01 66 B
02 77 A
02 53 B
我需要一个查询:
我认为请求应在Sequence上包含一个group by,但我无法使其正常工作
有人可以帮忙吗?
答案 0 :(得分:4)
使用条件聚合
select
id,
avg(case when type='A' then NR end) as 'AVG(NR A)' ,
avg(case when type='B' then NR end) as 'AVG(NR B)',
avg(case when type in ('A','B') then NR end) as 'AVG(NR)'
from tablename
group by id