sql is not working correctly
Posted on 2014-09-19
I need this to only return the amount that I retrieved on the first select. If I sum it again, the amount are wrong. Unfortunately, this is the only sql that seems to work with PHP.
with Orders as (select ohscdt "Date", SUM(OHMTO$) "Amount" from kivalib.orhdrpf where OHSTAT = \'F\' AND OHTYP = 1 and ohscdt > \'' . $ymd . '\' ' . $company . ' ' .
'group by ohscdt ORDER BY OHSCDT) ' .
'SELECT ohordt, sum(ord."Amount") ' .
'FROM KIVALIB.ORHDRPF left outer join Orders ord on ord."Date" = ohordt ' .
'WHERE ohordt > ' . $ymd . ' ' .
'GROUP BY ohordt ORDER BY OHORDT',