select 序号=(select count(*) from 表 where 日期<'2004年5月' and 日期<=a.日期),
[2004年5月以前的A值]=aa.A,
[2004年5月以后的A值]=bb.A
from (select * from 表 where 日期<'2004年5月') aa,
(select * from 表 where 日期>'2004年5月') bb
where (select count(*) from 表 where 日期<'2004年5月' and 日期<=a.日期)
=(select count(*) from 表 where 日期>'2004年5月' and 日期<=b.日期)
[2004年5月以前的A值]=aa.A,
[2004年5月以后的A值]=bb.A
from (select * from 表 where 日期<'2004年5月') aa,
(select * from 表 where 日期>'2004年5月') bb
where (select count(*) from 表 where 日期<'2004年5月' and 日期<=a.日期)
=(select count(*) from 表 where 日期>'2004年5月' and 日期<=b.日期)
[2004年5月以前]=sum(case when 字段B<'2004-5-1' then A else 0 end),
[2004年5月以后]=sum(case when 字段B>='2004-5-1' then A else 0 end)
from table
sum(case when B>='2004-05-01' then A else 0 end)
from 表