我有两个表
table1: a ,b
table2:c
1
2
.....
我要实现:
select sum(a),sum(b) from table1 where 按table2:c中的字段,分别做汇总,C中有很多条记录
例如:
select sum(a),sum(b) from table1 where x=table2.c中的1
select sum(a),sum(b) from table1 where x=table2.c中的2
.....
table1: a ,b
table2:c
1
2
.....
我要实现:
select sum(a),sum(b) from table1 where 按table2:c中的字段,分别做汇总,C中有很多条记录
例如:
select sum(a),sum(b) from table1 where x=table2.c中的1
select sum(a),sum(b) from table1 where x=table2.c中的2
.....
SELECT
'SUM1'=(SELECT SUM(A) FROM TABLE1 WHERE A.C=X ),
FROM TABLE2 A
具体可参见相关子查询概念
有没办法循环得到table2中每一条记录的值啊,table2中只有一个字段
然后我在用这个值分别去汇总
select sum(a),sum(b) from table1 where x in (select 2 from table2)不知道是不是LZ要的意思