现在有两个表,t1 和 t2
其中:t1有字段a int,b numeric,c numeric,d numeric
t2有字段a int,bc numeric,val numeric
纪录:
t1:
a b c d
1 5 9 2.5
2 10 14 3
t2:
a bc val
1 5 24
1 6 42
1 6.5 30
1 7 80
我想统计sum(bc)*d where b=
1<bc=<c (="" (24+42+30+80)*2.5="" (30+80)*3="" 1="" 14="" 2.5="" 3="" 5="" 6.5="" 9="" \---------------------------------------------------------------="" a="" a,b,c,d,sum(val)*d="" and="" as="" b="" c="" d="" e="" from="" select="" t1="" t1:="" where="" x,t2="" x.a="y.a" x.a,x.b,x.c,x.d,y.val="" x.b<="y.bc" x.c="" y="" 应该怎样写sql,谢谢各位仁兄,贤妹="" 最后结果为="">=y.bc
2) as z
3group by a,b,c,d
4
5
6
7\---------------------------------------------------------------
8
9select t1.*,sum(t2.val)*t1.d as e from t1,t2 where
10t1.b<=t2.bc and t2.bc<=t1.c
11group by t1.a,t1.b,t1.c,t1.d
12
13\---------------------------------------------------------------
14
15select
16a.*,
17(select sum(val)*a.d from b where bc between a.b and a.c group by a) as e
18from t1 a,t2 b
19where b.a=a.a
20
21很不理解上面的写法本人经过实际测试发现上面的写发都是错误的
22希望以后大家发贴子的时候自己先测试一下,免得误导他人.</bc=<c>