美文网首页
数据库,列转行,相同ID逗号连接SQL

数据库,列转行,相同ID逗号连接SQL

作者: 蚁丶点 | 来源:发表于2018-07-27 17:46 被阅读0次

    SELECT c1, SUBSTR (MAX (SYS_CONNECT_BY_PATH (c2, ',')), 2) NAME

    FROM (SELECT c1, c2, rn, LEAD (rn) OVER (PARTITION BY c1 ORDER BY rn) rn1

    FROM (SELECT c1, c2, ROW_NUMBER () OVER (ORDER BY c2) rn

    FROM (select b.id c1,a.id c2 from hrm_emp.hrm_sys_base_code_t a,hrm_emp.hrm_sys_code_type_t b

    where a.code_type_id=b.id

    and a.code_type_id=7)))

    START WITH rn1 IS NULL

    CONNECT BY rn1 = PRIOR rn

    GROUP BY c1;

    select b.id c1,a.id c2 from hrm_emp.hrm_sys_base_code_t a,hrm_emp.hrm_sys_code_type_t b

    where a.code_type_id=b.id

    and a.code_type_id=7 可灵活切换

    相关文章

      网友评论

          本文标题:数据库,列转行,相同ID逗号连接SQL

          本文链接:https://www.haomeiwen.com/subject/hqvgmftx.html