MSSQL 经典SQL 语句--使用PIOVT 行转列

行转列 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')
    )
上一篇:【ios开发】ios开发问题集锦


下一篇:vSphere Client开启虚拟机提示:出现了常规系统错误: 由于目标计算机积极拒绝,无法连接。