zoukankan      html  css  js  c++  java
  • Oracle 10gR2 行变列研究

      Oracle 10gR2 行变列研究

        建立测试数据和环境:

    create table test(
     COUNTRY 
    varchar2(20),
     CITY  
    varchar2(20) )
    insert into test(COUNTRY,CITY) VALUES('中国','上海');
    commit;
    insert into test(COUNTRY,CITY) VALUES('中国','湖北');
    commit;
    insert into test(COUNTRY,CITY) VALUES('中国','天津');
    commit;
    insert into test(COUNTRY,CITY) VALUES('美国','纽约');
    commit;
    insert into test(COUNTRY,CITY) VALUES('美国','华盛顿');
    commit;

       实现结果:

    中国       天津,湖北,上海
    美国       华盛顿,纽约

     编写代码如下:

    select country, 
    max(decode(city,'上海',city,null))||','||max(decode(city,'湖北',city,null))
    ||','||max(decode(city,'天津',city,null))  from test  GROUP by country
  • 相关阅读:
    今天我正式走出公司...
    PHP图片处理函数
    PHP缓存知识-转载
    Nginx 服务器伪静态配置实例
    PHP防止跨站攻击的脚本
    <
    <
    <- OPENGL 10 NormalMAP ->
    <-OPENGL 9-> 阴影篇
    - OPENGL8
  • 原文地址:https://www.cnblogs.com/zping/p/1311178.html
Copyright © 2011-2022 走看看