from #tmp3
得到如下数据 #tmp3
order_date 2006-1-4 |
startdate 2006-1-1 |
enddate 2006-1-4 |
2006-1-5 | 2006-1-1 | 2006-1-5 |
2006-1-6 | 2006-1-1 | 2006-1-6 |
2006-1-9 | 2006-1-1 | 2006-1-9 |
2006-1-10 | 2006-1-1 | 2006-1-10 |
2006-1-11 | 2006-1-1 | 2006-1-11 |
from #tmp2
得到如下
order_date 2006-1-4 |
type china |
family_code hid |
damount 415615.3 |
2006-1-5 | china | hid | 2052-1-4 |
2006-1-6 | ulc | el | 148597.1 |
2006-1-9 | ulc | el | 229007.5 |
2006-1-10 | china | el | 102882.5 |
2006-1-11 | china | el | 113491.4 |
我用你上面的查询的话,加上group by type,family_code 他会报错
查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。那我要实现分类汇总的话要如何做呢??
select order_date,
(
select sum(Damount)
from #tmp2
where order_date between
(
select startdate from #tmp3
where a.order_date=#tmp3.order_date
)
and
(
select enddate from #tmp3
where a.order_date=#tmp3.order_date
)
group by type,family_code
) as Tamount
from #tmp3 a
[此贴子已经被作者于2006-5-31 13:33:28编辑过]