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 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛