oracle数据库分组查询,使用聚合函数

sql:

<!--获取资金监管协议统计页面数据-->
<select id="getZjjgxyCountData" parameterType="com.gtmap.fundsupervision.dto.ZjjgxyCountSearchDto" resultType="com.gtmap.fundsupervision.vo.ZjjgxyCountVo">
    select f3.dgfkyhmc as "jgyh",count(f3.dgfkyhmc) as "jgsl",sum(f4.fwmj) as "jzmj",sum(f1.htzje) as "cjje",sum(f1.zjgje) as "jgje",sum(f3.je) as "rzje",sum(f6.je) as "zqje"
    from FCJY_CLF_ZJJGXY f1
    join FCJY_CYZT_CYQYJBXX f2
    on f1.jgfwjgbh = f2.qyid
    join FCJY_CLF_ZJJGRZJL f3
    on f1.jgid = f3.jgid
    join FCJY_CLF_ZJJGHT f4
    on f1.jgid = f4.jgid
    join FCJY_CLF_ZJJGCZJL f6
    on f1.jgid = f6.jgid
    <where>
        <if test="searchJyrq != null and searchJyrq != ''">
            to_char(f1.qdxyrq,'yyyy-mm-dd') = #{
    
    searchJyrq}
        </if>
        <if test="searchJsrq != null and searchJsrq != ''">
            and to_char(f1.gdsj,'yyyy-mm-dd') = #{
    
    searchJsrq}
        </if>
        <if test="searchXyzt != null and searchXyzt != ''">
            and f1.zt like '%${searchXyzt}%'
        </if>
    </where>
    group by f3.dgfkyhmc
</select>

注意
group by 后面的字段必须是 select 中的未进行聚合函数操作的所有字段,缺一个都不行。

猜你喜欢

转载自blog.csdn.net/qq_38152400/article/details/112543685