求助:group by 语句
主叫 被叫
aa 17909-22
aa 22
aa 3317909
aa 17909-3317909
aa 17909-333
aa 333
aa 3333
aa 17909-3333
得到
主叫 被叫 拨打次数
aa 22 2
aa 3317909 2
aa 333 2
aa 3333 2
create table bb
(主叫 char(10),
被叫 char(20))
insert into bb
select 'aa ' , '17909-22 '
union all
select 'aa ' , '22 '
union all
select 'aa ' , '3317909 '
union all
select 'aa ' , '17909-3317909 '
union all
select 'aa ' , '17909-333 '
union all
select 'aa ' , '333 '
union all
select 'aa ' , '3333 '
union all
select 'aa ' , '17909-3333 '
谢谢!
------解决方案----------------------try
create table bb
(主叫 varchar(10),
被叫 varchar(20))
insert into bb
select 'aa ' , '17909-22 '
union all
select 'aa ' , '22 '
union all
select 'aa ' , '3317909 '
union all
select 'aa ' , '17909-3317909 '
union all
select 'aa ' , '17909-333 '
union all
select 'aa ' , '333 '
union all
select 'aa ' , '3333 '
union all
select 'aa ' , '17909-3333 '
select 主叫,replace(被叫, '17909- ', ' ') as 被叫, 拨打次数=count(*)
from bb
group by 主叫,replace(被叫, '17909- ', ' ')
------解决方案--------------------同上
------解决方案--------------------create table bb
(主叫 char(10),
被叫 char(20))
insert into bb
select 'aa ' , '17909-22 '
union all
select 'aa ' , '22 '
union all
select 'aa ' , '3317909 '
union all
select 'aa ' , '17909-3317909 '
union all
select 'aa ' , '17909-333 '
union all
select 'aa ' , '333 '
union all
select 'aa ' , '3333 '
union all
select 'aa ' , '17909