本帖最后由 shunjiankunle 于 2012-04-27 10:56:07 编辑

解决方案 »

  1.   

    如果表里面是时间字段
    select * from tab where to_char(date,'yyyy') = 输入的年份;
    这样是否可以
    另外,头像哪儿来的呀,好萌的妹子
      

  2.   


    统计当然是连年带月一起统计。你没表没数据,给个SQL有什么用,打几个田字格都能说明白的问题说不明白。
      

  3.   

    条件设成to_char(date,'yyyy-MM')<to_char(sysdate,'yyyy-MM')试试
      

  4.   

    传入一个参数 年份 构造一个月份表来左联你的表 查询每月数据select to_char(add_months(to_date('2011'||'01-01','yyyy-mm-dd'),level-1),'yyyy-mm') mon
    from dual
    connect by level <= (select case when 2011=to_char(sysdate,'yyyy') then to_number(to_char(sysdate,'mm')) else 12 end a from dual)
    --参数2011
          mon
    -----------------
    1 2011-01
    2 2011-02
    3 2011-03
    4 2011-04
    5 2011-05
    6 2011-06
    7 2011-07
    8 2011-08
    9 2011-09
    10 2011-10
    11 2011-11
    12 2011-12
    --参数2012
          mon
    -----------------
    1 2012-01
    2 2012-02
    3 2012-03
    4 2012-04
      

  5.   

    这一大堆SQL看的人眼晕……下面是按自己理解写的-- 如果是往年的记录就显示12个月份的记录 如果是今年的就显示当前月份之前的记录,根据年份判断可以得出时间范围,一个开始时间,一个结束时间,以这两个时间作为条件查询
    --例如传入年份year(格式yyyy)--得到开始时间(闭区间):不管传入的是哪一年,肯定都是从传入年份的一月一日开始查
    select to_date(year||'0101','yyyymmdd') from dual;--得到结束时间(开区间):如果是往年,传入年份第二年的1月1日;如果是今年,本月1日
    select decode(to_number(to_char(sysdate, 'yyyy')) - to_number(year),
                  0,
                  to_date(to_char(sysdate, 'yyyymm') || '01', 'yyyymmdd'),
                  to_date((to_number(year) + 1) || '0101', 'yyyymmdd'))
      from dual;
    --比如时间字段是time,where条件就是:where time<decode(to_number(to_char(sysdate, 'yyyy')) - to_number(year),
                  0,
                  to_date(to_char(sysdate, 'yyyymm') || '01', 'yyyymmdd'),
                  to_date((to_number(year) + 1) || '0101', 'yyyymmdd'))
    and time>=to_date(year||'0101','yyyymmdd')