select SUBSTR(timekey,1,10) as tk,SUM(num) as nn
from owntable
where SUBSTR(TIME_KEY,1,8) = 'year' & 'month' & 'day'
GROUP BY SUBSTR(timekey,1,10);这个是asp里直接用的查询,那个 'year' & 'month' & 'day'代表3个查询关键字的意思,数据库中的timekey包括年、月、日、时间、时区,所以要和在一起查谢谢各位帮帮忙~~~~~

解决方案 »

  1.   

    select to_char(to_date('&年'||'&月'||'&日','yyyymmdd')+(rownum-1)/24,'hh24:mi') from user_tables where rownum<25;不用写临时表
      

  2.   

    能解释一下+(rownum-1)/24,'hh24:mi')是什么意思吗?谢谢
      

  3.   

    rownum:行号。第一行为1,第二行为2因为你是要求从00:00开始,故用rownum-1(rownum-1)/24: 表示一日之中的第几个小时。to_char(...)将()中的...用hh24:mi这个格式输出,也就是你要求的把整个这句话放到SQLPLUS中去运行,输入完三个参数后,就能得到你要的结果。利用这个结果集和你的表去关联,就能得到你想要的了
      

  4.   

    哦~~有些明白,我忘记说了,数据库里的数据可能某一个小时有很多条,所以,选取的是个sum
    select SUBSTR(timekey,1,10) as tk,SUM(hujiaoshu) as nn
    from owntable
    where SUBSTR(TIME_KEY,1,8) = 'year' & 'month' & 'day'
    GROUP BY SUBSTR(timekey,1,10);
    这段是我需要的字段,是表中的一部分,而且每个都是计算值,怎么做呢?谢谢了:)
      

  5.   

    有点问题的,timekey里面有时间,格式为2004121617HCK这样的,也就是年月日时时区,直接用这个的话如果没有00点只有19点的数据,它显示在00点的位置~~~怎么让它显示在19点的位置?而且每个字段的结果是个sum,也就是19点可能有3条数据,是这3条数据的和
      

  6.   

    select a.*,b.* from 
    (
       select to_char(to_date('&年'||'&月'||'&日','yyyymmdd')+(rownum-1)/24,'hh24:mi') hourid from 
         user_tables 
       where rownum<25
    ) a,
    (
       select SUBSTR(timekey,9,10) as tk,SUM(hujiaoshu) as nn
         from owntable
         where SUBSTR(TIME_KEY,1,8) = 'year' & 'month' & 'day'
         GROUP BY SUBSTR(timekey,9,10);
    ) b
    where a.hourid=b.tk(+);就是这种意思,具体的你要到你的程序中去调
      

  7.   

    select a.*,b.* from 
    (
       select to_char(to_date('2003'||'12'||'03','yyyymmdd')+(rownum-1)/24,'hh24:mi') hourid
       from table 
       where rownum<25
    ) a,
    (
       select SUBSTR(TIME_KEY,1,10) AS TIMEKEYR,SUM(N_ABANDONED) AS NABANDONED
         from table
         where SUBSTR(TIME_KEY,1,8) like '20031203%'
         GROUP BY SUBSTR(TIME_KEY,1,10)
    ) b
    where a.hourid = b.TIMEKEYR(+);为何没有数据??这个对么?这天肯定有数据的
      

  8.   

    select a.*,b.* from 
    (
       select to_char(to_date('2003'||'12'||'03','yyyymmdd')+(rownum-1)/24,'hh24') hourid
       from table 
       where rownum<25
    ) a,
    (
       select SUBSTR(TIME_KEY,1,10) AS TIMEKEYR,SUM(N_ABANDONED) AS NABANDONED
         from table
         where SUBSTR(TIME_KEY,1,8) like '20031203%'
         GROUP BY SUBSTR(TIME_KEY,1,10)
    ) b
    where a.hourid = b.TIMEKEYR(+);这样呢?
      

  9.   

    select a.*,b.* from 
    (
       select to_char(to_date('2003'||'12'||'03','yyyymmdd')+(rownum-1)/24,'yyyymmddhh24') hourid
       from gendmt.R_ROUTEPOINT_HOUR 
       where rownum<25
    ) a,
    (
       select SUBSTR(TIME_KEY,1,10) AS TIMEKEYR,SUM(N_ABANDONED) AS NABANDONED,SUM(T_ABANDONED) AS TABANDONED,SUM(N_ANSWERED) AS NANSWERED,SUM(N_ENTERED) AS NENTERED
         from gendmt.R_ROUTEPOINT_HOUR 
       --  where SUBSTR(TIME_KEY,1,8) like '20031203%'
         GROUP BY SUBSTR(TIME_KEY,1,10)
    ) b
    where a.hourid = b.TIMEKEYR(+);
    已解决,非常感谢:)
    请问一下那个(+)什么意思?
      

  10.   

    where a.hourid = b.TIMEKEYR(+); Left Outer Joinwhere a.hourid(+) = b.TIMEKEYR; Right Outer Join