有这个一个纵向表,表结构如下:表名: c2
字段名:
metid   测量点编码  number
toutype 分时类型    number
valuetype  测量值类型 number
mettime    测量时间   date
rawvalue   测量值     number
---------------------------------
其中
toutype(分时类型) 的值分别为 1(高峰),2(平峰),3(低谷),9(总)
valuetype(测量值类型)的值分别为 1(代表:正向有功),2(反向有功),3(正向无功),4(反向无功)
---------------------------------
数据如下:
METID      TOUTYPE  VALUETYPE METTIME        RAWVALUE
1001000051 1 1 2003-6-7 4305
1001000051 1 1 2003-6-7 00:05 4306
1001000051 1 1 2003-6-7 00:10 4308
1001000051 1 1 2003-6-7 00:15 4309
1001000051 1 1 2003-6-7 00:20 4313
1001000051 1 1 2003-6-7 00:25 4315
1001000051 1 1 2003-6-7 00:30 4319
1001000051 1 1 2003-6-7 00:35 4322
1001000051 1 1 2003-6-7 00:40 4323
1001000051 1 1 2003-6-7 00:45 4326
1001000051 1 1 2003-6-7 00:50 4330
1001000051 1 1 2003-6-7 00:55 4334
1001000051 1 1 2003-6-7 01:00 4335
1001000051 1 2 2003-6-7 5183
1001000051 1 2 2003-6-7 00:05 5188
1001000051 1 2 2003-6-7 00:10 5193
1001000051 1 2 2003-6-7 00:15 5195
1001000051 1 2 2003-6-7 00:20 5200
1001000051 1 2 2003-6-7 00:25 5203
1001000051 1 2 2003-6-7 00:30 5206
1001000051 1 2 2003-6-7 00:35 5209
1001000051 1 2 2003-6-7 00:40 5210
1001000051 1 2 2003-6-7 00:45 5213
1001000051 1 2 2003-6-7 00:50 5217
1001000051 1 2 2003-6-7 00:55 5220
1001000051 1 2 2003-6-7 01:00 5224
1001000051 1 3 2003-6-7 5219
1001000051 1 3 2003-6-7 00:05 5223
1001000051 1 3 2003-6-7 00:10 5226
1001000051 1 3 2003-6-7 00:15 5229
1001000051 1 3 2003-6-7 00:20 5232
1001000051 1 3 2003-6-7 00:25 5233
1001000051 1 3 2003-6-7 00:30 5237
1001000051 1 3 2003-6-7 00:35 5238
1001000051 1 3 2003-6-7 00:40 5242
1001000051 1 3 2003-6-7 00:45 5244
1001000051 1 3 2003-6-7 00:50 5246
1001000051 1 3 2003-6-7 00:55 5249
1001000051 1 3 2003-6-7 01:00 5254
1001000051 1 4 2003-6-7 5156
1001000051 1 4 2003-6-7 00:05 5159
1001000051 1 4 2003-6-7 00:10 5160
1001000051 1 4 2003-6-7 00:15 5162
1001000051 1 4 2003-6-7 00:20 5167
1001000051 1 4 2003-6-7 00:25 5172
1001000051 1 4 2003-6-7 00:30 5175
1001000051 1 4 2003-6-7 00:35 5178
1001000051 1 4 2003-6-7 00:40 5181
1001000051 1 4 2003-6-7 00:45 5183
1001000051 1 4 2003-6-7 00:50 5184
1001000051 1 4 2003-6-7 00:55 5188
1001000051 1 4 2003-6-7 01:00 5192
1001000051 2 1 2003-6-7 5140
1001000051 2 1 2003-6-7 00:05 5141
1001000051 2 1 2003-6-7 00:10 5144
1001000051 2 1 2003-6-7 00:15 5149
1001000051 2 1 2003-6-7 00:20 5150
1001000051 2 1 2003-6-7 00:25 5153
1001000051 2 1 2003-6-7 00:30 5158
1001000051 2 1 2003-6-7 00:35 5163
1001000051 2 1 2003-6-7 00:40 5167
1001000051 2 1 2003-6-7 00:45 5172
1001000051 2 1 2003-6-7 00:50 5177
1001000051 2 1 2003-6-7 00:55 5180
1001000051 2 1 2003-6-7 01:00 5182
1001000051 2 2 2003-6-7 5140
1001000051 2 2 2003-6-7 00:05 5141
1001000051 2 2 2003-6-7 00:10 5144
1001000051 2 2 2003-6-7 00:15 5149
1001000051 2 2 2003-6-7 00:20 5150
1001000051 2 2 2003-6-7 00:25 5153
1001000051 2 2 2003-6-7 00:30 5158
1001000051 2 2 2003-6-7 00:35 5163
1001000051 2 2 2003-6-7 00:40 5167
1001000051 2 2 2003-6-7 00:45 5172
1001000051 2 2 2003-6-7 00:50 5177
1001000051 2 2 2003-6-7 00:55 5180
1001000051 2 2 2003-6-7 01:00 5182
1001000051 2 3 2003-6-7 5107
1001000051 2 3 2003-6-7 00:05 5109
1001000051 2 3 2003-6-7 00:10 5113
1001000051 2 3 2003-6-7 00:15 5115
1001000051 2 3 2003-6-7 00:20 5116
1001000051 2 3 2003-6-7 00:25 5121
1001000051 2 3 2003-6-7 00:30 5125
1001000051 2 3 2003-6-7 00:35 5128
1001000051 2 3 2003-6-7 00:40 5132
1001000051 2 3 2003-6-7 00:45 5137
1001000051 2 3 2003-6-7 00:50 5140
1001000051 2 3 2003-6-7 00:55 5143
1001000051 2 3 2003-6-7 01:00 5145
1001000051 2 4 2003-6-7 5085
1001000051 2 4 2003-6-7 00:05 5090
1001000051 2 4 2003-6-7 00:10 5091
1001000051 2 4 2003-6-7 00:15 5095
1001000051 2 4 2003-6-7 00:20 5097
1001000051 2 4 2003-6-7 00:25 5098
1001000051 2 4 2003-6-7 00:30 5103
1001000051 2 4 2003-6-7 00:35 5104
1001000051 2 4 2003-6-7 00:40 5108
1001000051 2 4 2003-6-7 00:45 5113
1001000051 2 4 2003-6-7 00:50 5115
1001000051 2 4 2003-6-7 00:55 5116
1001000051 2 4 2003-6-7 01:00 5117
1001000051 3 1 2003-6-7 5189
1001000051 3 1 2003-6-7 00:05 5192
1001000051 3 1 2003-6-7 00:10 5197
1001000051 3 1 2003-6-7 00:15 5201
1001000051 3 1 2003-6-7 00:20 5202
1001000051 3 1 2003-6-7 00:25 5205
1001000051 3 1 2003-6-7 00:30 5210
1001000051 3 1 2003-6-7 00:35 5211
1001000051 3 1 2003-6-7 00:40 5213
1001000051 3 1 2003-6-7 00:45 5214
1001000051 3 1 2003-6-7 00:50 5219
1001000051 3 1 2003-6-7 00:55 5224
1001000051 3 1 2003-6-7 01:00 5229
1001000051 3 2 2003-6-7 5296
1001000051 3 2 2003-6-7 00:05 5301
1001000051 3 2 2003-6-7 00:10 5306
1001000051 3 2 2003-6-7 00:15 5311
1001000051 3 2 2003-6-7 00:20 5315
1001000051 3 2 2003-6-7 00:25 5319
1001000051 3 2 2003-6-7 00:30 5322
1001000051 3 2 2003-6-7 00:35 5323
1001000051 3 2 2003-6-7 00:40 5326
1001000051 3 2 2003-6-7 00:45 5331
1001000051 3 2 2003-6-7 00:50 5335
1001000051 3 2 2003-6-7 00:55 5339
1001000051 3 2 2003-6-7 01:00 5341
1001000051 3 3 2003-6-7 5076
1001000051 3 3 2003-6-7 00:05 5077
1001000051 3 3 2003-6-7 00:10 5081
1001000051 3 3 2003-6-7 00:15 5082
1001000051 3 3 2003-6-7 00:20 5085
1001000051 3 3 2003-6-7 00:25 5086
1001000051 3 3 2003-6-7 00:30 5088
1001000051 3 3 2003-6-7 00:35 5092
1001000051 3 3 2003-6-7 00:40 5095
1001000051 3 3 2003-6-7 00:45 5098
1001000051 3 3 2003-6-7 00:50 5099
1001000051 3 3 2003-6-7 00:55 5101
1001000051 3 3 2003-6-7 01:00 5103
1001000051 3 4 2003-6-7 5167
1001000051 3 4 2003-6-7 00:05 5169
1001000051 3 4 2003-6-7 00:10 5172
1001000051 3 4 2003-6-7 00:15 5174
1001000051 3 4 2003-6-7 00:20 5179
1001000051 3 4 2003-6-7 00:25 5184
1001000051 3 4 2003-6-7 00:30 5188
1001000051 3 4 2003-6-7 00:35 5192
1001000051 3 4 2003-6-7 00:40 5193
1001000051 3 4 2003-6-7 00:45 5194
1001000051 3 4 2003-6-7 00:50 5196
1001000051 3 4 2003-6-7 00:55 5199
1001000051 3 4 2003-6-7 01:00 5201
1001000051 9 1 2003-6-7 5254
1001000051 9 1 2003-6-7 00:05 5258
1001000051 9 1 2003-6-7 00:10 5262
1001000051 9 1 2003-6-7 00:15 5265
1001000051 9 1 2003-6-7 00:20 5269
1001000051 9 1 2003-6-7 00:25 5272
1001000051 9 1 2003-6-7 00:30 5273
1001000051 9 1 2003-6-7 00:35 5276
1001000051 9 1 2003-6-7 00:40 5278
1001000051 9 1 2003-6-7 00:45 5280
1001000051 9 1 2003-6-7 00:50 5283
1001000051 9 1 2003-6-7 00:55 5284
1001000051 9 1 2003-6-7 01:00 5286
1001000051 9 2 2003-6-7 5140
1001000051 9 2 2003-6-7 00:05 5145
1001000051 9 2 2003-6-7 00:10 5148
1001000051 9 2 2003-6-7 00:15 5150
1001000051 9 2 2003-6-7 00:20 5153
1001000051 9 2 2003-6-7 00:25 5155
1001000051 9 2 2003-6-7 00:30 5159
1001000051 9 2 2003-6-7 00:35 5162
1001000051 9 2 2003-6-7 00:40 5165
1001000051 9 2 2003-6-7 00:45 5166
1001000051 9 2 2003-6-7 00:50 5167
1001000051 9 2 2003-6-7 00:55 5172
1001000051 9 2 2003-6-7 01:00 5174
1001000051 9 3 2003-6-7 5224
1001000051 9 3 2003-6-7 00:05 5225
1001000051 9 3 2003-6-7 00:10 5228
1001000051 9 3 2003-6-7 00:15 5233
1001000051 9 3 2003-6-7 00:20 5235
1001000051 9 3 2003-6-7 00:25 5240
1001000051 9 3 2003-6-7 00:30 5242
1001000051 9 3 2003-6-7 00:35 5243
1001000051 9 3 2003-6-7 00:40 5246
1001000051 9 3 2003-6-7 00:45 5250
1001000051 9 3 2003-6-7 00:50 5254
1001000051 9 3 2003-6-7 00:55 5255
1001000051 9 3 2003-6-7 01:00 5260
1001000051 9 4 2003-6-7 5152
1001000051 9 4 2003-6-7 00:05 5154
1001000051 9 4 2003-6-7 00:10 5156
1001000051 9 4 2003-6-7 00:15 5159
1001000051 9 4 2003-6-7 00:20 5163
1001000051 9 4 2003-6-7 00:25 5167
1001000051 9 4 2003-6-7 00:30 5170
1001000051 9 4 2003-6-7 00:35 5171
1001000051 9 4 2003-6-7 00:40 5173
1001000051 9 4 2003-6-7 00:45 5178
1001000051 9 4 2003-6-7 00:50 5179
1001000051 9 4 2003-6-7 00:55 5184
1001000051 9 4 2003-6-7 01:00 5188
=======================================================

解决方案 »

  1.   

    我想要的横向表如下: 后面还有几个列,我就不写了
    高峰正向有功就是指:toutype = 1 and valuetype =1
    高峰反向有功就是指:toutype = 1 and valuetype =2
    高峰正向无功就是指:toutype = 1 and valuetype =3
    高峰反向无功就是指:toutype = 1 and valuetype =4
    平峰正向有功就是指:toutype = 2 and valuetype =1
    平峰反向有功就是指:toutype = 2 and valuetype =2
    平峰正向无功就是指:toutype = 2 and valuetype =3
    平峰反向无功就是指:toutype = 2 and valuetype =4
    低谷正向有功就是指:toutype = 3 and valuetype =1
    低谷反向有功就是指:toutype = 3 and valuetype =2
    低谷正向无功就是指:toutype = 3 and valuetype =3
    低谷反向无功就是指:toutype = 3 and valuetype =4
    总正向有功就是指:toutype = 9 and valuetype =1
    总反向有功就是指:toutype = 9 and valuetype =2
    总正向无功就是指:toutype = 9 and valuetype =3
    总反向无功就是指:toutype = 9 and valuetype =4
    ===============================================================
    metid     mettime 高峰正向有功 平峰正向有功 低谷正向有功 高峰反向有功 平峰反向有功 低谷反向有功
    1001000051 2003-6-7 00:00   4305         5140
    1001000051 2003-6-7 00:05   4306         5141
    1001000051 2003-6-7 00:10   4308         5144
    1001000051 2003-6-7 00:15   4309         5149
    1001000051 2003-6-7 00:20   4313         5150 
    1001000051 2003-6-7 00:25   4315         5153
    1001000051 2003-6-7 00:30   4319  5158
    1001000051 2003-6-7 00:35   4322  5161
    .
    .
    .
    .
    .
    .
    我知道可以使用decode解决这个问题,但是就是不知道怎么写.
      

  2.   

    SQL*PLus> desc emp;
     名称                                      是否为空? 类型
     ----------------------------------------- -------- -----------------------
     EMPNO                                              NUMBER(4)
     ENAME                                              VARCHAR2(10)
     JOB                                                VARCHAR2(9)
     MGR                                                NUMBER(4)
     HIREDATE                                           DATE
     SAL                                                NUMBER(7,2)
     COMM                                               NUMBER(7,2)
     DEPTNO                                             NUMBER(2)SQL*PLus> select job, deptno, count(*)
      2       from emp
      3       group by job, deptno;JOB           DEPTNO   COUNT(*)
    --------- ---------- ----------
    CLERK             10          2
    CLERK             20          4
    CLERK             30          2
    ANALYST           20          4
    MANAGER           10          2
    MANAGER           20          2
    MANAGER           30          2
    SALESMAN          30          8
    PRESIDENT         10          2已选择9行。SQL*PLus> select job,
      2          max( decode( deptno, 10, cnt, null ) ) dept_10,
      3          max( decode( deptno, 20, cnt, null ) ) dept_20,
      4          max( decode( deptno, 30, cnt, null ) ) dept_30,
      5          max( decode( deptno, 40, cnt, null ) ) dept_40
      6        from ( select job, deptno, count(*) cnt
      7               from emp
      8               group by job, deptno )
      9      group by job
     10     /JOB          DEPT_10    DEPT_20    DEPT_30    DEPT_40
    --------- ---------- ---------- ---------- ----------
    ANALYST                       4
    CLERK              2          4          2
    MANAGER            2          2          2
    PRESIDENT          2
    SALESMAN                                 8
      

  3.   

    我的这个问题已经被杂牌上的一个MM给解决了,SQL语句如下:
    select t.metid,t.mettime,
      sum(decode(t.toutype||t.valuetype,'11',t.rawvalue)) as 高峰正向有功,
      sum(decode(t.toutype||t.valuetype,'12',t.rawvalue)) as 高峰反向有功,
      sum(decode(t.toutype||t.valuetype,'13',t.rawvalue)) as 高峰正向无功,
      sum(decode(t.toutype||t.valuetype,'14',t.rawvalue)) as 高峰反向无功,
      sum(decode(t.toutype||t.valuetype,'21',t.rawvalue)) as 平峰正向有功,
      sum(decode(t.toutype||t.valuetype,'22',t.rawvalue)) as 平峰反向有功,
      sum(decode(t.toutype||t.valuetype,'23',t.rawvalue)) as 平峰正向无功,
      sum(decode(t.toutype||t.valuetype,'24',t.rawvalue)) as 平峰反向无功,
      sum(decode(t.toutype||t.valuetype,'31',t.rawvalue)) as 低谷正向有功,
      sum(decode(t.toutype||t.valuetype,'32',t.rawvalue)) as 低谷反向有功,
      sum(decode(t.toutype||t.valuetype,'33',t.rawvalue)) as 低谷正向无功,
      sum(decode(t.toutype||t.valuetype,'34',t.rawvalue)) as 低谷反向无功,
      sum(decode(t.toutype||t.valuetype,'91',t.rawvalue)) as 总正向有功,
      sum(decode(t.toutype||t.valuetype,'92',t.rawvalue)) as 总反向有功,
      sum(decode(t.toutype||t.valuetype,'93',t.rawvalue)) as 总正向无功,
      sum(decode(t.toutype||t.valuetype,'94',t.rawvalue)) as 总反向无功
    from cmetvalue2 t
    group by t.metid,t.mettime
    ==========================================================================
    源贴如下:
    http://jinesc.6600.org/bbs/disp.asp?idd=50606&room=115
    谢谢 jonics