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)
    )

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

上一篇:oracle 19c已经安装好了但没有scott用户,如何创建新的scott用户?


下一篇:linux调试程序GDB的常用命令