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

Count of ID and cost per month

$
0
0

SELECT pr.PurchaseRequestId,
pr.DateRequested,
   DATENAME( month, pr.DateRequested) AS DateRequested,
   SUM(prl.TotalCost) AS TotalCost,
  COUNT(pr.DateRequested) AS CountOFPRIDINMONTH
  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

Result:

PurchaseRequestId    DateRequested    DateRequested    TotalCost    CountOFPRIDINMONTH
885                           2013-05-21              May                       100.00     1
886                           2013-05-21             May                         100.00    1
894                            2013-05-21            May                      2470.00    4
918                           2013-06-12            June                         240.00    1
919                        2013-06-12  7          June                         250.00    2

I am looking for the result as

MONTH   CountofPurchaseRequestIdinMonth   TotalCost

MAY          6                                                       2670

June         3                                                       490

How can get this ? can anyone suggest me please

Thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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