sql - how do i combine two selects from one table where one has a GROUP BY and the other has a DISTINCT -


both of these work individually

select  ponumber,          count(requestnumber) "innumofrequests",          sum(amount) "sumofamounts"  tableview group ponumber    select distinct ponumber,                  (10 * ceiling((datediff(day,poapproveddate,getdate()))/10))                    "binofdayssincepoapproved"                       tableview 

and want end 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 po1 po 2 requests , poapproved data , amount same 2 requests.

it seems easy book i'm using (the language of sql) can't figure out.
:(
alex

select *    (          select ponumber, count(requestnumber) "innumofrequests", sum(amount) "sumofamounts"            tableview           group ponumber         ) a,         (          select distinct ponumber, (10 * ceiling((datediff(day, poapproveddate, getdate()))/10)) "binofdayssincepoapproved"            tableview         ) b  a.ponumber = b.ponumber 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -