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
    关注

    望采纳,这个不好帮忙

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

报告相同问题?

悬赏问题

  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码