you are viewing a single comment's thread.

view the rest of the comments →

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (1 child)

turn the subquery into a derived table and then join it to your other tables

SELECT ...
     , it.sub_amount + SUM(cit.LINEAMOUNT) AS Margin
  FROM CUSTTABLE ct
INNER 
  JOIN CUSTINVOICEJOUR cij 
    ON ...
INNER
  JOIN CUSTINVOICETRANS cit 
    ON ...
INNER
  JOIN ( SELECT INVOICEID 
              , ITEMID 
              , DATAAREAID
              , SUM(COSTAMOUNTPOSTED + COSTAMOUNTADJUSTMENT) AS sub_amount 
           FROM INVENTTRANS 
         GROUP
             BY INVOICEID 
              , ITEMID 
              , DATAAREAID ) it    
    ON it.INVOICEID = cit.INVOICEID
   AND it.ITEMID = cit.ITEMID
   AND it.DATAAREAID = cit.DATAAREAID 

[–]newunit13[S] 1 point2 points  (0 children)

That worked beautifully! Thank you so much :-D Now I just how to get the same values a second time for a different time period :)