Both of these work individually
SELECT PONumber,
count(RequestNumber) as "InNumOfRequests",
sum(Amount) as "SumofAmounts"
FROM tableView
GROUP BY PONumber
SELECT DISTINCT PONumber,
(10 * ceiling((DATEDIFF(day,POApprovedDate,GETDATE()))/10))
AS "BINofDaysSincePOApproved"
FROM tableView
And I want to end up with:
PONumber | InNumOfRequests | SumofAmounts | BINofDaysSincePOApproved
PO1 | 2 | 100 | 180
PO2 | 1 | 50 | 179
tableView looks like:
RequestNumber | PONumber | Amount | POApproved Date
1 | PO1 | 100.00 | 2010-01-01
2 | PO1 | 100.00 | 2010-01-01
3 | PO2 | 50.00 | 2010-01-02
note that PO1 is actually the PO for 2 requests and so the POApproved Data and Amount is the same for those 2 requests.
It seems easy but from the book I'm using (The Language of SQL) i can't figure it out.
Help :(
Alex