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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿