日期:2014-05-18  浏览次数:20519 次

求SQL語句﹐實現記錄的合并﹐急﹗﹗﹗在線等
求SQL語句﹐實現記錄的合并﹐急﹗﹗﹗在線等:
我有表A﹐表B
A(DOCid,Jobid,item_no,quantity)
B(item_no,item_desc)
select   A.DOCid,A.Jobid,A.item_no,A.quantity,B.item_desc
from   A   INNER   JOIN   B   on   A.item_no=B.item_no
得到數據為:
DOCid   Jobid     item_no       quantity     item_desc

DF001   PP001     E001                 24               化學01
DF002   PP001     E001                 30               化學01  

現在我想只得到DF002這條記錄﹐   DF001去掉﹐但在DF002中quantity要加上DF002中的quantity﹐想得到結果是﹕

DF002   PP001     E001                 54               化學01


急﹗﹗請大家幫幫忙﹗﹗﹗

------解决方案--------------------
select A.DOCid,A.Jobid,A.item_no,SUM(A.quantity) As quantity,B.item_desc
from A INNER JOIN B on A.item_no=B.item_no
Group By A.DOCid,A.Jobid,A.item_no, B.item_desc

------解决方案--------------------
看錯了

select Min(A.DOCid) As DOCid,A.Jobid,A.item_no,SUM(A.quantity) As quantity,B.item_desc
from A INNER JOIN B on A.item_no=B.item_no
Group By A.Jobid,A.item_no, B.item_desc