SQL 递归查询 以及列转字段行

递归查询:

SELECT
    *
FROM
    表名 START WITH 条件 CONNECT BY PRIOR 子字段 = 父字段
    AND 条件 ORDER SIBLINGS BY 字段 ASC

列转字段行:

SELECT
    *
FROM
    (
        SELECT
            TRANS_AMT,
            TRANS_TYPE
        FROM
            表名
        WHERE
            条件
    ) PIVOT(
        SUM( TRANS_AMT ) FOR TRANS_TYPE IN(
            '转账入账' AS transferIn_Count,
            '转账出账' AS transferOut_Count,
            '企业提现' AS withDraw_Count,
            '企业网银充值' AS recharge_Count
        )
    )

你可能感兴趣的:(SQL 递归查询 以及列转字段行)