select a.a,a.b,c=sum(c.b)
from 表A a,表B b,表C c
where b.id=c.id
and b.a like a.a+'%'
group by a.a,a.b
from 表A a,表B b,表C c
where b.id=c.id
and b.a like a.a+'%'
group by a.a,a.b
解决方案 »
- 死锁问题求指导
- 求简单合并sql
- SQL Server 与此同时ODBC 为什么总是连不上,跪求????
- 在线急等exec执行含有变量的SQL语句的问题!
- ◤100分,疯掉了◥关于按照出现的词频统计并排序的问题
- sql有没有办法将多表联查的列头名称提取出来?
- 请问ResultSet与left join使用的问题,为何会抛错?SQLServerException: 无法从已删除行获取值
- temp目录下有个文件有几百兆,这是什么原因?
- SQL远程访问共享文件夹并将文件备份到本地
- 日志中的内容如何查看和删除?因为它越来越大,而我跟本用不着它……
- 请问一个存储过程的问题
- 怎样将数据库中一个表导入到另一个数据库中?
create table 表A(a varchar(10),b varchar(10),c bit)
insert 表A select '01' ,'人员支出',0
union all select '0101' ,'工资' ,0
union all select '010101','出差费' ,1
union all select '010102','加班费' ,1
union all select '0102' ,'资金' ,1
union all select '02' ,'集体支出',0
union all select '0201' ,'文具' ,1 create table 表B(id int,a varchar(10))
insert 表B select 1,'010101'
union all select 2,'010101'
union all select 3,'010102'
union all select 4,'0102'
union all select 5,'0201'create table 表C(ID int,b int)
insert 表C select 1,20
union all select 2,40
union all select 3,30
union all select 4,50
union all select 5,10
go--查询
select a.a,a.b,c=sum(c.b)
from 表A a,表B b,表C c
where b.id=c.id
and b.a like a.a+'%'
group by a.a,a.b
order by a.a
go--删除测试
drop table 表A,表B,表C/*--测试结果a b c
---------- ---------- -----------
01 人员支出 140
0101 工资 90
010101 出差费 60
010102 加班费 30
0102 资金 50
02 集体支出 10
0201 文具 10(所影响的行数为 7 行)--*/
我都写晕了,怎么就没想到,呵呵
试一下,晚上结贴