首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一条查询语句解决办法

2012-03-04 
求一条查询语句A表:matercodematernummaterindatedepot100152007-05-075100262007-05-075B表matercodemate

求一条查询语句
A表:
matercode     maternum     materindate   depot
1001                 5                   2007-05-07     5
1002                 6                   2007-05-07     5


B表
matercode     maternum     materindate   depot
1001                 6                   2007-05-07     5


如何使查询结果为
matercode     maternum     materindate   depot
1001                 11                 2007-05-07       5
1002                 6                   2007-05-07       5
也就是说.相同的matercode中的maternum要加在一起.



[解决办法]
--try

select matercode,sum(maternum) as maternum,materindate,depot
from
(
select * from A
union all
select * from B
)as tmp
group by matercode,materindate,depot

热点排行