表a:
ID DETAIL NO ACCOUNT
1 A 1 100
2 C 1 50
3 B 2 40
表b:
ID NO NUMBER
1 1 350
2 2 200
3 1 100我要得到:满足NO=1的account 和 number 的分类汇总
select sum(a.account),sum(b.number) from a join b on a.no=b.no where a.no=1
但结果不是 150,450
ID DETAIL NO ACCOUNT
1 A 1 100
2 C 1 50
3 B 2 40
表b:
ID NO NUMBER
1 1 350
2 2 200
3 1 100我要得到:满足NO=1的account 和 number 的分类汇总
select sum(a.account),sum(b.number) from a join b on a.no=b.no where a.no=1
但结果不是 150,450
解决方案 »
- sql server 2005 关系图主键外键钥匙方向感觉反了啊
- 存储过程,如何判断某一中间查询的结果数
- 远程连接SQL Server2000
- 我用VM虚拟了一个WINDOWS SERVER 2003出来,如何在这个虚拟的系统中运行SQL SERVER 2005?
- ACCESS中的自动编号字段与SQL中的那个类型是一样的.也可以自动编号?
- Reporting Services用表达式取值的问题
- ldf如何打开,机上没装SQL,能用小软件打开吗
- 如何用SQL统计?
- 关于SQL Server2000(sp4)服务莫名其妙停止的问题
- 如何实现随机查询?紧急。。。。
- “群发消息功能”数据库设计中的问题
- 这个sql语句如何实现
(select sum(acccount) from a where no=1) as Aaccount,
(select sum(number) from b where no=1) as Baccount
(id int identity(1,1),
detail char(1),
no int,
account int)
insert a(detail,no,account)
select 'A',1,100 UNION ALL
select 'C',1,50 UNION ALL
select 'B',2,100
--select * from acreate table b
(id int identity(1,1),
no int,
number int)
insert b(no,number)
select 1,350 union all
select 2,200 union all
select 1,100
--select * from bselect
(select sum(account) from a where no=1) as Aaccount,
(select sum(number) from b where no=1) as Baccountdrop table a,b
from (
select ACCOUNT,0 as [number]
from a
where [no]=1
union all
select 0 as ACCOUNT,[number]
from b
where [no]=1
) as t