zoukankan      html  css  js  c++  java
  • 【pg 列转行】大大的实用主义

    CREATE TABLE highTable
    (
      id serial NOT NULL,
      value integer,
      name character varying,
      zbfm character varying,
      CONSTRAINT pkey PRIMARY KEY (id)
    )
    
    insert into highTable values ('甲','年龄',12);
    insert into highTable values ('甲','身高',95);
    insert into highTable values ('甲','体重',31);
    insert into highTable values ('乙','年龄',13);
    insert into highTable values ('乙','身高',67);
    insert into highTable values ('乙','体重',23);
    insert into highTable values ('丙','年龄',15);
    insert into highTable values ('丙','身高',85);
    insert into highTable values ('丙','体重',56);
    insert into highTable values ('丁','身高',89);
    insert into highTable values ('丁','年龄',36);
    insert into highTable values ('丁','体重',76);
    
    
    select name
        ,string_agg((case zbfm when '年龄' then value::varchar end),'') as 年龄
        ,string_agg((case zbfm when '身高' then value::varchar end),'') as 身高
        ,string_agg((case zbfm when '体重' then value::varchar end),'') as 体重
    from highTable
    GROUP BY 1;
    

      

  • 相关阅读:
    matplotlib绘制常见统计图
    学习进度(14)
    hive的基本用法(2)
    hive的基本用法(1)
    进度日报表10
    进度日报表09
    进度日报表08
    进度日报表07
    第六周总结
    进度日报表06
  • 原文地址:https://www.cnblogs.com/czsblog/p/15335913.html
Copyright © 2011-2022 走看看