select a.id,a.CustomID,a.Name,sales=sum(b.sales)
from A join B on a.CustomID=b.CustomID
group by a.id,a.CustomID,a.Name
解决方案 »
- 求助一道关于Sql Server 2005里面触发器的题目
- 求SQL语句替换大于连续九位的数字为空值
- 关于游标在视图及存储过程中使用的问题
- 想要合并两个表的列数据到另一张表中,但不想产生笛卡尔积
- 关于2表关联的SQL 语句!
- SQL数据库权限问题
- 请问视图和存储过程在数据库导出时为何不能成功导出?
- 致歉: 由于《T-SQL 2 Tips》有错,请相关用户速打此补丁: K4-911 !
- 求一SQL语句 急!!!!
- 本地数据库和通过WEBSERVICES操作的远程数据库(在INTERNET上)能使用分布式事务吗?
- 谢谢Hahahahahaha CCEO
- 请问:如何进行完数据库操作以后不写入操作日志啊?需要什么参数?谢谢各位大侠
from A left join B on a.CustomID=b.CustomID
group by a.id,a.CustomID,a.Name
create table A(ID int,CustomID int,Name varchar(10))
insert A select 1,1001,'张三'
union all select 2,1002,'李四'
union all select 3,1003,'王五'create table B(ID int,CustomID int,sales decimal(10,2))
insert B select 1,1002,59.00
union all select 2,1001,77.00
union all select 3,1002,65.00
union all select 4,1002,88.00
go--查询统计
select a.id,a.CustomID,a.Name,sales=sum(b.sales)
from A left join B on a.CustomID=b.CustomID
group by a.id,a.CustomID,a.Name
go--删除测试
drop table a,b/*--测试结果
id CustomID Name sales
----------- ----------- ---------- -------------
1 1001 张三 77.00
2 1002 李四 212.00
3 1003 王五 NULL(所影响的行数为 3 行)--*/
from A left join B on a.CustomID=b.CustomID
group by a.id,a.CustomID,a.Name
from A B
where A.customID=B.customID可不可以这样啊?
from A ,B --加逗号
where A.customID=B.customID
group by group by a.id,a.CustomID,a.Name --加group by
本来我得A表有很多字段,是不是group by 语句要包含所有的字段?