求一Oracle sql 语句 计算次数问题
表 request
code1 code2
A B
A D
C B
B D
计算每个字母出现的次数 也就是要得到以下结果
code count
A 2
B 3
C 1
D 2
------解决方案--------------------create table request(code1 varchar2(10),code2 varchar2(10));
///
insert into request
select 'A ', 'B ' from dual
union all
select 'A ', 'D ' from dual
union all
select 'C ', 'B ' from dual
union all
select 'B ', 'D ' from dual;
///
select code,count(code) from
(
select code1 code from request
union all
select code2 code from request
) t
group by code