create table 表(年 int,月 int,客户 char(1))
insert into 表 select 2000,1,'A'
insert into 表 select 2000,2,'A'
insert into 表 select 2000,2,'B'
insert into 表 select 2000,3,'C'
insert into 表 select 2000,3,'A'
insert into 表 select 2000,3,'D'
insert into 表 select 2000,4,'B'
insert into 表 select 2000,4,'E'select
distinct b.年,b.月,a.客户
from
表 a,表 b
where
a.年 = b.年 and a.月 <= b.月
order by
b.年,b.月
insert into 表 select 2000,1,'A'
insert into 表 select 2000,2,'A'
insert into 表 select 2000,2,'B'
insert into 表 select 2000,3,'C'
insert into 表 select 2000,3,'A'
insert into 表 select 2000,3,'D'
insert into 表 select 2000,4,'B'
insert into 表 select 2000,4,'E'select
distinct b.年,b.月,a.客户
from
表 a,表 b
where
a.年 = b.年 and a.月 <= b.月
order by
b.年,b.月
from 表 a,表 b
where a.年>=b.年 and a.月>=b.月 and a.客户<>b.客户
from 表 a,表 b
where a.年>=b.年 and a.月>=b.月 and a.客户<>b.客户
group by a.年,a.月,isnull(a.客户,b.客户) as 客户