zoukankan      html  css  js  c++  java
  • sql group by 和 定义输出的小数位数

    select job_name, ft_brch,LINE_cover,incre_cover,commit_id, compa_with,create_date
        from functest_buids_info,hole_functest,incre_functest 
        where functest_buids_info.id=hole_functest.build_info_id and functest_buids_info.id=incre_functest.build_info_id
        and incre_cover>=0 and functest_buids_info.job_name like "api%%" and ft_brch='master'
        and create_date > "2020-05-22" and create_date <= "2020-06-06"
        order by job_name, create_date desc) 

    使用以上sql的结果,同一个job_name,结果记录有重复,为了一个job只拿一个最新的结果改为使用group by,详细如下:

     select job_name,ft_brch, max(LINE_cover) , max(incre_cover) , max(compa_with), max(create_date) from (
    
        (
        select job_name, ft_brch,LINE_cover,incre_cover,commit_id, compa_with,create_date
        from functest_buids_info,hole_functest,incre_functest 
        where functest_buids_info.id=hole_functest.build_info_id and functest_buids_info.id=incre_functest.build_info_id
        and incre_cover>=0 and functest_buids_info.job_name like "api%%" and ft_brch='master'
        and create_date > "2020-05-22" and create_date <= "2020-06-06"
        order by job_name, create_date desc) 
        as a )
        group by job_name

    注:当使用group by时,select后面的字段的值如果是重复的,则可直接使用字段,如果不是重复的值的字段,则需要使用聚合函数。

    如,max(LINE_cover)

    结果 LINE_cover和incre_cover原本只是4位小数,搜索结果却成了N位小数,好吧,不明白。然后sql改为如下CAST(max(LINE_cover) AS decimal(9,4)),定义输出的小数为4位:

            select job_name,ft_brch, CAST(max(LINE_cover) AS decimal(9,4)), CAST(max(incre_cover) AS decimal(9,4)), max(compa_with), max(create_date) from (
    
        (
        select job_name, ft_brch,LINE_cover,incre_cover,commit_id, compa_with,create_date
        from functest_buids_info,hole_functest,incre_functest 
        where functest_buids_info.id=hole_functest.build_info_id and functest_buids_info.id=incre_functest.build_info_id
        and incre_cover>=0 and functest_buids_info.job_name like "api%%" and ft_brch='master'
        and create_date > "2020-05-22" and create_date <= "2020-06-06"
        order by job_name, create_date desc) 
        as a )
        group by job_name
  • 相关阅读:
    适用于ASP.NET的留言本(翻译)
    大足石刻一日游
    Zonet 宽带路由器eMule端口映射设置
    在公式编辑器中使用键盘
    TAU G2的错误信息:TSC0134: Transition must end with stop, nextstate or join action
    Sony DV的CCD也是有问题的
    使用UltraEdit实现从UNIX文件到DOS文件的批量转换
    在PowerPoint中改变公式编辑器的颜色
    如何在Visual Studio.NET 2003下编译ANTLR 2.77
    如何修复修复损坏的TAU G2的.u2文件
  • 原文地址:https://www.cnblogs.com/jxba/p/13066432.html
Copyright © 2011-2022 走看看