Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL Total help

$
0
0

SELECT Datename(month, pr.daterequested)        AS Month,
       pr.purchaserequestid,
       Count(pr.purchaserequestid)              AS COUNTOFPRID,
       Sum(prl.totalcost)                       AS TotalCost
FROM   dbo.purchaserequest AS pr
       LEFT JOIN dbo.purchaserequestlineitem AS prl
              ON pr.purchaserequestid = prl.purchaserequestid
WHERE  prl.totalcost IS NOT NULL
GROUP  BY pr.daterequested,
          pr.purchaserequestid,
          Datename(month, pr.daterequested)

Result:

Month    Purchaserequestid    CountofPRID    TotalCost
June                           918           1                    240.00
June                           919           2                    250.00
May                            885           1                   100.00
May                            886           1                  100.00
May                            894           4                   2470.00

I want the result to be: i want each month how may PR are there and wahts the cost

Month         CountofPRID    TotalCost

June               2                      490

May                3                     2670


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>