weixin_42892965 2019-03-05 13:54 采纳率: 36.8%
浏览 1210
已采纳

oracle 通过月份表来查询季度的数据

现在的要求就是查询出 指定年的第几季度到指定年的第几季度的数据
下面是我写的一段代码 就是查询 季度到季度之间 只显示一个季度 判断条件不知该怎么写

<select id="findJi" resultType="java.util.HashMap">
    select distinct
    <foreach collection="table" item="employeeId" index="index"
        open="" close="" separator="">
        <choose>
            <when test="employeeId!=null and employeeId!=''">
                Round(avg(${employeeId})over(partition by year),2)
                as b${index},
            </when>
            <when test="employeeId==null and employeeId==''">
                '' as b${index}
            </when>
        </choose>

    </foreach>
    <if test="cnzTable!=null and cnzTable!=''">
        <foreach collection="cnzTable" item="cnz" index="index"
            open="" close="" separator="">
            <choose>
                <when test="cnz!=null and cnz!=''">
                    (select Round(avg(${cnz}),2) from T_SQ_DATA_STATISTIC_MONTH c
                    where STATION_ID=${stationName} and
                    <!-- decode(month_order,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4) 
                        between ${sJi} and ${eJi} -->
                    decode(c.month_order,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4)>=to_number(${sJi})
                    and
                    decode(c.month_order,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4) <![CDATA[<=]]>to_number(${eJi})
                    ) as a${index},
                </when>
                <when test="cnz==null and cnz==''">
                    '' as a${index}
                </when>
            </choose>
        </foreach>
    </if>
    <if test="cnzTable==null or cnzTable==''">
        <foreach collection="table" item="employeeId" index="index"
            open="" close="" separator="">
            <choose>
                <when test="employeeId!=null and employeeId!=''">
                    (select Round(avg(${employeeId}),2) from T_MSIS_BE_HIST_MONTH d
                    where
                    STATION_ID=t.STATION_ID
                    <!-- and decode(month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4) 
                        between ${sJi} and ${eJi} -->
                    and
                    decode(d.month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4)>=to_number(${sJi})
                    and
                    decode(d.month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4) <![CDATA[<=]]>to_number(${eJi})
                    )as a${index} ,
                </when>
                <when test="employeeId==null and employeeId==''">
                    '' as a${index}
                </when>
            </choose>
        </foreach>
    </if>
    (year||'年'||decode(decode(t.month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4),'1','春季','2','夏季','3','秋季','4','冬季'))
    data1
    from T_MSIS_BE_HIST_MONTH t
    where
    STATION_ID=${stationName}
    <!-- and decode(t.month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4) 
        between ${sJi} and ${eJi} -->
    and
    decode(t.month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4)>=to_number(${sJi})
    and
    decode(t.month,'1',1,'2',1,'3',1,'4',2,'5',2,'6',2,'7',3,'8',3,'9',3,'10',4,'11',4,'12',4) <![CDATA[<=]]>to_number(${eJi})
    and t.year>=to_number(${start}) and t.year <![CDATA[<=]]>to_number(${end})
    order by data1
</select>

求大神帮帮忙

  • 写回答

1条回答 默认 最新

  • _TongJie 2019-03-05 15:17
    关注

    望采纳,这个不好帮忙

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!