/*
看看下面的SQL怎么写 ![]() ![]() | |||
---|---|---|---|
|
|
*/
--data:
create table sa
(
s01 nvarchar2(20)
,s02 nvarchar2(10)
,s03 int
)
insert into sa values('200801','200805',100);
insert into sa values('200802','',0);
insert into sa values('200803','',0);
insert into sa values('200804','',0);
insert into sa values('200805','200810',200);
insert into sa values('200806','',0);
insert into sa values('200807','',0);
insert into sa values('200810','200812',300);
insert into sa values('200811','',0);
commit;
--sql:
select sa.s01,min(sb.s02),min(sb.s03) from
sa,
(select s01,s02,s03 from sa
where s02 is not null
and s01<s02 ) sb
where sa.s01<sb.s02
group by sa.s01
--result:
200801 200805 100
200802 200805 100
200803 200805 100
200804 200805 100
200805 200810 200
200806 200810 200
200807 200810 200
200810 200812 300
200811 200812 300