呵呵,真要是如你所述的需求这么简单,ORACLE是很容易实现的,几个SELECT 语句就搞定

解决方案 »

  1.   

    输入参数:p_date
    select sum (b)
      from mytable
     where trunc (c
                , decode (p_date
                        , trunc (p_date, 'DDD'), 'DDD'
                        , trunc (p_date, 'MON'), 'MON'
                        , trunc (p_date, 'YYYY'), 'YYYY'
                        , 'YYYY'
                         )
                 ) = nvl (p_date, trunc (c, 'YYYY'));
      

  2.   

    刚才忘了处理小时了
    select sum (b)
      from mytable
     where trunc (c
                , decode (p_date
                        , trunc (p_date, 'HH'), 'HH'  -- 小时
                        , trunc (p_date, 'DDD'), 'DDD' -- 天
                        , trunc (p_date, 'MON'), 'MON' -- 月
                        , trunc (p_date, 'YYYY'), 'YYYY' -- 年
                        , 'YYYY'
                         )
                 ) = nvl (p_date, trunc (c, 'YYYY'));
      

  3.   

    KingSunSha(弱水三千),坛上好久没见过你,回国了吗?
      

  4.   

    xieyongan(没钱途) :
    你好!
    确实很久没来了,我还在国外。一直忙于工作,最近项目才开始平静下来。
      

  5.   

    第一次有三个星星的给我回答问题啊!!!!!!!!!!!!select sum (b)
      from mytable
     where trunc (c
                , decode (p_date
                        , trunc (p_date, 'DDD'), 'DDD'
                        , trunc (p_date, 'MON'), 'MON'
                        , trunc (p_date, 'YYYY'), 'YYYY'
                        , 'YYYY'
                         )
                 ) = nvl (p_date, trunc (c, 'YYYY'));
    可是我不明白这个是一个什么啊?存储过程还是什么啊?
    我的
    mnc是[email protected]希望能认识大家啊
      

  6.   

    小妹妹,KingSunSha(弱水三千),是我的偶像,技术水平高,人缘好,乐于助人,可惜现在在国外挣US$,当时还要走的时候,很多人舍不得
    ---以上题外话你可以写成一个函数或在脚本里直接调用。
      

  7.   

    如果写成函数可以再加个exception,就OK
      

  8.   

    trunc怎么用呀,SQL> SELECT TRUNC(TO_DATE('27-11-1992', 'DD-MM-YYyy'), 'DAY')
      2      "First Of The Year"
      3          FROM DUAL;First Of The Year
    -----------------
    1992-11-22  
    怎么会有这种情况?
      

  9.   

    多给分非星星了啊!
    星星的也不在乎这点分啊!
    非常感谢大家!
    但是我没看明白这个阿我最后用的方法是SELECT to_char(字段,'yyyy-mm') AS a, COUNT(  * ) As b from table WHERE 
     POSTTIME BETWEEN  TIMESTAMP '2004-01-01 00:00:00' AND TIMESTAMP '2005-01-01 00:00:00' 
      GROUP BY to_char(字段,'yyyy-mm')