行转列 ORCAL 示例 (pivot) MSSQL 相同 废话不多说,直接上demo:
select * from( select fmaterialid, fassistunitid, zdate, sumQty from ( select entry.fmaterialid, entry.fassistunitid, to_char( bill.FBIZDATE, 'yyyy-mm-dd') zdate, sum(entry.fassistqty) sumQty from T_IM_SALEISSUEENTRY entry left join T_IM_SALEISSUEBILL bill on bill .fid = entry.fparentid where to_char(bill.FBIZDATE, 'yyyy-mm-dd') >= '2018-04-03' and to_char(bill.FBIZDATE, 'yyyy-mm-dd') <= '2018-04-05' group by entry.fmaterialid, entry.fassistunitid, bill.fbizdate) ) tpivot(sum(sumQty) for zdate in ('2018-04-031', '2018-04-05') )