1
SELECT  b.BranchName ,
        pm.AgreementValue
FROM    dbo.Member AS m
        INNER JOIN dbo.PlanMaster AS pm ON ( m.PlanId = pm.PlanId )
        INNER JOIN dbo.Branch AS b ON ( b.BranchId = m.BranchId )

これは上記のクエリの結果です

BranchName      AgreementValue
------------------------------
abc             60000.00
abc             36000.00
abc             36000.00
xyz             20000.00
xyz             10000.00

今、私はAgreementValue BranchNameの合計を取得したい..助けてくれてありがとう

4

2 に答える 2

2

GROUP BY b.BranchNameSUMそのように:

SELECT   b.BranchName ,
         SUM(pm.AgreementValue) TotalValue
FROM     dbo.Member AS m
         INNER JOIN dbo.PlanMaster AS pm ON ( m.PlanId = pm.PlanId )
         INNER JOIN dbo.Branch AS b ON ( b.BranchId = m.BranchId )
GROUP BY b.BranchName;
于 2013-01-10T12:32:23.547 に答える
0

各行の合計を取得しようとしている場合は、次のウィンドウ関数を使用しますsum()

SELECT  b.BranchName ,
        pm.AgreementValue,
        sum(pm.AgreementValue) over (partition by b.BranchName) as BranchTotal
FROM    dbo.Member AS m
        INNER JOIN dbo.PlanMaster AS pm ON ( m.PlanId = pm.PlanId )
        INNER JOIN dbo.Branch AS b ON ( b.BranchId = m.BranchId )
于 2013-01-10T14:40:38.583 に答える