加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Postgresql行列转换

发布时间:2020-12-13 16:39:27 所属栏目:百科 来源:网络整理
导读:列转行 1 查询测试表数据 [html] view plain copy cqdb = select*fromtest; name ------ AA BB CC (3rows) 2 列转行(string_agg) selectstring_agg(name,',')fromtest; string_agg ------------ AA,BB,CC (1row) 行转列 ----------- A,B,C,D,E (1row) 2 行

列转行

1 查询测试表数据

[html] view plain copy
  1. cqdb=>select*fromtest;
  2. name
  3. ------
  4. AA
  5. BB
  6. CC
  7. (3rows)
2 列转行(string_agg)

>selectstring_agg(name,',')fromtest;

  • string_agg
  • ------------
  • AA,BB,CC
  • (1row)

  • 行转列

    -----------

  • A,B,C,D,E
  • (1row)
  • 2 行转列(regexp_split_to_table)

    >selectregexp_split_to_table(name,248);">regexp_split_to_table

  • -----------------------
  • A
  • B
  • C
  • D
  • E
  • (5rows)
  • (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读