我想查test表的某年的12个月每个月份的数据,怎么写呀..请大哥们帮帮忙.

解决方案 »

  1.   

    请给出表结构及部分数据(最好以INSERT形式给出,方便解答人做测试),以及想要的结果,这样才方便回答问题.
      

  2.   

    to_char(sysdate,'mm')='12' 
    这个怎么放到select 后面啊?
    就一个时间字段,
    跟据这个时间字段反回12个月的数据就行
      

  3.   

    我是想一条SQL语句,实在没办法,我就一个读一次吧..select 
          ((sum(case to_char(previous_month,'mm') when '01' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a1,
          ((sum(case to_char(previous_month,'mm') when '02' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a2,
          ((sum(case to_char(previous_month,'mm') when '03' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a3,
          ((sum(case to_char(previous_month,'mm') when '04' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a4,
          ((sum(case to_char(previous_month,'mm') when '05' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a5,
          ((sum(case to_char(previous_month,'mm') when '06' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a6,
          ((sum(case to_char(previous_month,'mm') when '07' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a7,
          ((sum(case to_char(previous_month,'mm') when '08' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a8,
          ((sum(case to_char(previous_month,'mm') when '09' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a9,
          ((sum(case to_char(previous_month,'mm') when '10' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a10,
          ((sum(case to_char(previous_month,'mm') when '11' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a11,
          ((sum(case to_char(previous_month,'mm') when '12' then score else 0 end )-(max(score)+min(score)))/(count(*)-2)) as a12
    from evaluate t
    where referee_id in  (select operator_id from operator where role_id =163) and operator_id=213如果我的01月份数据是0然后sum(0)再-去后面的(max(score)+min(score)))/(count(*)-2)) 就会出错,我不知道怎么判断.
      

  4.   


    select (sum(score)-(max(score)+min(score)))/(count(*)-2) from evaluate group by to_char(previous_month,'yyyymm');可以试试
      

  5.   


    select (sum(score)-(max(score)+min(score)))/(count(*)-2) from evaluate group by to_char(previous_month,'yyyymm');可以试试