表tj(帐号,金额)
表zh(帐号,类别)
表lb(类别) value(a,b,c,d...)
现在要统计tj表中的金额,条件是表tj中的帐号在表zh中并且zh中的类别等于表lb中的值(要按lb表中的数据分别统计,如有5条就分别统计5条,lb中的值不是固定的a,b,c,d...)
例如:select sum(金额) from tj where 帐号 in (select 帐号 from zh where 类别 = 'a')
类别 = 'a'中的条件在另一个表中
table lb(a,b,c,d....)中的值不是固定a,b...
我要按表lb中的数据分别做汇总
如:
select sum(金额) from tj where 帐号 in (select 帐号 from table where 类别 = 'a')
select sum(金额) from tj where 帐号 in (select 帐号 from table where 类别 = 'b')
select sum(金额) from tj where 帐号 in (select 帐号 from table where 类别 = 'c')
.....
表zh(帐号,类别)
表lb(类别) value(a,b,c,d...)
现在要统计tj表中的金额,条件是表tj中的帐号在表zh中并且zh中的类别等于表lb中的值(要按lb表中的数据分别统计,如有5条就分别统计5条,lb中的值不是固定的a,b,c,d...)
例如:select sum(金额) from tj where 帐号 in (select 帐号 from zh where 类别 = 'a')
类别 = 'a'中的条件在另一个表中
table lb(a,b,c,d....)中的值不是固定a,b...
我要按表lb中的数据分别做汇总
如:
select sum(金额) from tj where 帐号 in (select 帐号 from table where 类别 = 'a')
select sum(金额) from tj where 帐号 in (select 帐号 from table where 类别 = 'b')
select sum(金额) from tj where 帐号 in (select 帐号 from table where 类别 = 'c')
.....
from tj a join zh b on a.账号=b.账号 join lb c on b.类别=c.类别
group by c.类别这个怎么样?