zoukankan      html  css  js  c++  java
  • postgresql 行转列,拼接字符串

    create table k_user (
       op_id                VARCHAR(36)          not null,
       op_name              VARCHAR(100)         not null,
       password             VARCHAR(100)         not null,
       real_name            VARCHAR(100)         not null,
       lock_mark            VARCHAR(50)          not null,
       dept_no              TEXT                 null,
       post_id              TEXT                 null,
       tel                  VARCHAR(30)          null,
       mail                 VARCHAR(50)          null,
       create_id            VARCHAR(36)          not null,
       create_name          VARCHAR(100)         not null,
       create_time          VARCHAR(17)          not null,
       modify_id            VARCHAR(36)          null,
       modify_name          VARCHAR(100)         null,
       modify_time          VARCHAR(17)          null,
       remark               VARCHAR(1024)        null,
       constraint PK_K_USER primary key (op_id)
    );
    create table k_user_role (
       user_id              VARCHAR(36)          not null,
       role_id              VARCHAR(36)          not null,
       constraint PK_K_USER_ROLE primary key (user_id, role_id)
    );
    create table k_role (
       op_id                VARCHAR(36)          not null,
       op_name              VARCHAR(100)         not null,
       create_id            VARCHAR(36)          not null,
       create_name          VARCHAR(100)         not null,
       create_time          VARCHAR(17)          not null,
       modify_id            VARCHAR(36)          null,
       modify_name          VARCHAR(100)         null,
       modify_time          VARCHAR(17)          null,
       remark               VARCHAR(1024)        null,
       constraint PK_K_ROLE primary key (op_id)
    );

    select * from (select u.*,     array_to_string ( ARRAY ( SELECT  role_id FROM k_user_role ur WHERE ur.user_id = u.op_id ),',' ) AS user_role,     array_to_string ( ARRAY ( SELECT  op_name FROM k_user_role ur,k_role r WHERE ur.role_id=r.op_id and ur.user_id = u.op_id ),',' ) AS role_name FROM  k_user u ) k_user  limit 15 offset 0

  • 相关阅读:
    《浏览器工作原理与实践》读书笔记(4)
    在django中使用原生sql语句
    异步任务 ---- django-celery
    vue上传视屏或者图片到七牛云
    django项目初始化
    mysql 更新并生成指定范围随机数
    opencv基本命令学习整理
    docker分配CPU、内存资源
    傅里叶分析
    websocket协议性能测试(jmeter版)
  • 原文地址:https://www.cnblogs.com/101key/p/5328574.html
Copyright © 2011-2022 走看看