我是以你的前面描述的写出来的语句如下:
select [datetime],(case a when 'a' then sum_a_num else 0 end) as sum_a_num,
(case a when 'b' then sum_a_num else 0 end) as sum_b_num,
(case a when 'd' then sum_a_num else 0 end) as sum_c_num
from (
select adate as [datetime],a,sum(anum) as sum_a_num
from (
select *,'a' as a from a
union all
select *,'b' as b from b
union all
select *,'d' as d from d
) m
group by a,adate
) n
[ 本帖最后由 tangyunzhong 于 2010-10-30 21:02 编辑 ]
select [datetime],(case a when 'a' then sum_a_num else 0 end) as sum_a_num,
(case a when 'b' then sum_a_num else 0 end) as sum_b_num,
(case a when 'd' then sum_a_num else 0 end) as sum_c_num
from (
select adate as [datetime],a,sum(anum) as sum_a_num
from (
select *,'a' as a from a
union all
select *,'b' as b from b
union all
select *,'d' as d from d
) m
group by a,adate
) n
[ 本帖最后由 tangyunzhong 于 2010-10-30 21:02 编辑 ]