• Oracle表操作 (未完待续)


    1. Oracle 中将一个表中数据导入到另外一个表的方法

    insert into  scd_data_201007 select * from analog_data_201007 ;

    2. 纵表转换为横表

    纵表格式

    pid                   dtag    ttag    dqf      pval 

    1001-1-1001    100      1         0      10.10

    横表格式:

    pid    h1  h2  h3

    Select --Pid,Substr(Pid, 8, 4) As Dev_Type,
     Substr(Pid, 0, 6) As Dev_Type,
     To_Char(To_Date('20000101', 'yyyymmdd') + Dtag, 'YYYY-MM-DD') || ' ' ||
      Trunc(Ttag / 60) || ':00:00' As Datetime,
     -- Dtag, Ttag,
     Sum(Case Substr(Pid, 8, 4)
                  When '1001' Then
                   Pval
                  Else
                   0
          End) As Cy1,
     
     Sum(Case Substr(Pid, 8, 4)
                  When '1002' Then
                   Pval
                  Else
                   0
          End) As Cy2,
     Sum(Case Substr(Pid, 8, 4)
                  When '1003' Then
                   Pval
                  Else
                   0
          End) As Cy3,
     Sum(Case Substr(Pid, 8, 4)
                  When '1004' Then
                   Pval
                  Else
                   0
          End) As Cy4,
     Sum(Case Substr(Pid, 8, 4)
                  When '1005' Then
                   Pval
                  Else
                   0
          End) As Cy5,
     Sum(Case Substr(Pid, 8, 4)
                  When '1006' Then
                   Pval
                  Else
                   0
          End) As Cy6,
     Sum(Case Substr(Pid, 8, 4)
                  When '1007' Then
                   Pval
                  Else
                   0
          End) As Cy7,
     Sum(Case Substr(Pid, 8, 4)
                  When '1008' Then
                   Pval
                  Else
                   0
          End) As Cy8,
     Sum(Case Substr(Pid, 8, 4)
                  When '1009' Then
                   Pval
                  Else
                   0
          End) As C2h2,
     Sum(Case Substr(Pid, 8, 4)
                  When '1010' Then
                   Pval
                  Else
                   0
          End) As C2h6,
     Sum(Case Substr(Pid, 8, 4)
                  When '1011' Then
                   Pval
                  Else
                   0
          End) As Cy11,
     Sum(Case Substr(Pid, 8, 4)
                  When '1012' Then
                   Pval
                  Else
                   0
          End) As Cy12,
     Sum(Case Substr(Pid, 8, 4)
                  When '1013' Then
                   Pval
                  Else
                   0
          End) As Cy13,
     Sum(Case Substr(Pid, 8, 4)
                  When '1014' Then
                   Pval
                  Else
                   0
          End) As Cy14,
     Sum(Case Substr(Pid, 8, 4)
                  When '1015' Then
                   Pval
                  Else
                   0
          End) As Cy15,
     Sum(Case Substr(Pid, 8, 4)
                  When '1016' Then
                   Pval
                  Else
                   0
          End) As Cy16,
     Sum(Case Substr(Pid, 8, 4)
                  When '1017' Then
                   Pval
                  Else
                   0
          End) As Cy17,
     Sum(Case Substr(Pid, 8, 4)
                  When '1018' Then
                   Pval
                  Else
                   0
          End) As Cy18,
     Sum(Case Substr(Pid, 8, 4)
                  When '1019' Then
                   Pval
                  Else
                   0
          End) As Cy19
    
    From Analog_Data_200701
    --Where Dtag = '2558' And Ttag = '240' And Substr(Pid, 0, 6) = '1001-4'
    Group By Substr(Pid, 0, 6), Dtag, Ttag --, Pval
    Order By Dtag, Ttag, Substr(Pid, 0, 6)
    View Code

    3. Oracle 从已知表同步数据

    merge into sm_classes sc
    using (select * from ceibs_uv_embaclass) c
    on(sc.id = c.id)
    when matched then update
    set sc.classname=c.classname,sc.groupname=c.group_name
    when not matched then
    insert (sc.id,sc.classname,sc.groupname)values (c.id,c.classname,c.group_name)

    参考文章

    Oracle 中将一个表中数据导入到另外一个表的方法

    纵表转换为横表

    Oracle 从已知表同步数据

  • 相关阅读:
    mysql之创建数据库,创建数据表
    mysql之group by,order by
    一个人选出2门以上不及格的课程sql语句
    GIt入门
    数据库索引工作原理
    题目:50个人围城一圈数到3和3的倍数时出圈,问剩下的人是谁?原来的位置是多少?
    约瑟夫环:递归算法
    K-means算法的java实现,聚类分析681个三国武将
    java用一个for循环输出99乘法表
    写一个基于UDP协议的聊天小程序
  • 原文地址:https://www.cnblogs.com/arxive/p/5959166.html
Copyright © 2020-2023  润新知