兄弟们,我有多个表,其中每个表里都有个金额,用select 语句如何在一行到几个表的金额进行同累计呢?
a表
流水号 金额
001 300
002 50
b表
操作员 金额
zi 213
c表
客户 金额
张三 100如何得到
流水金额 操作金额 客户金额
350 213 100
a表
流水号 金额
001 300
002 50
b表
操作员 金额
zi 213
c表
客户 金额
张三 100如何得到
流水金额 操作金额 客户金额
350 213 100
(select sum(金额) 流水金额 from a) t1,
(select sum(金额) 操作金额 from b) t2,
(select sum(金额) 客户金额 from c) t3
drop table A
go
create table A(流水号 varchar(10),金额 int)
insert into A values('001', 300)
insert into A values('002', 50)
goif object_id('pubs..B') is not null
drop table B
go
create table B(操作员 varchar(10),金额 int)
insert into B values('zi',213)
goif object_id('pubs..C') is not null
drop table C
go
create table C(客户 varchar(10),金额 int)
insert into C values('张三',100)
goselect t1.流水金额,t2.操作金额,t3.客户金额 from
(select sum(金额) 流水金额 from a) t1,
(select sum(金额) 操作金额 from b) t2,
(select sum(金额) 客户金额 from c) t3drop table A,B,C/*
流水金额 操作金额 客户金额
----------- ----------- -----------
350 213 100(所影响的行数为 1 行)
*/
(select sum(流水金额) from a),
(select sum(操作金额) from b),
(select sum(客户金额) from c)
向你们学习!!!!!!
马上给分