zoukankan      html  css  js  c++  java
  • 修改查询语句字段返回样式

    1、时间字段

    <select id="selectMessage" resultType="map">
            select
              messageId,
              title,
              messageInfo,
               date_format( updateDate,'%Y-%m-%d %H:%i:%S') as updateDate
            from m_message
            where state=1
            and fabu=1
            order by updateDate desc
        </select>
    updateDate 的数据库格式为datatime

    2、为null添加默认值
    <select id="SumIn" resultType="map">
            select
            IFNULL(sum(materialsNum),0) as inSum
            from m_materials
            where classfiyId=#{classfiyId}
            and inOrOut=1
            and state=1
        </select>

    3、数据四舍五入

     

    在mysql中,round函数用于数据的四舍五入,它有两种形式:

    1、round(x,d)  ,x指要处理的数,d是指保留几位小数

    这里有个值得注意的地方是,d可以是负数,这时是指定小数点左边的d位整数位为0,同时小数位均为0;

    2、round(x)  ,其实就是round(x,0),也就是默认d为0;

    下面是几个实例

        1、查询: select round(1123.26723,2);

             结果:1123.27

        2、查询: select round(1123.26723,1);

             结果: 1123.3

        3、查询: select round(1123.26723,0);

             结果:1123

        4、查询: select round(1123.26723,-1);

             结果: 1120

        5、查询: select round(1123.26723,-2);

             结果:1100

        6、查询: select round(1123.26723);

             结果:1123

    4、拼接字段
      SELECT
                materialsNumber,
                GROUP_CONCAT(materialsName,':',materialsNum,unitName) as info 

    注意:使用 GROUP_CONCAT()函数必须对源数据进行分组,否则所有数据会被合并成一行

     
  • 相关阅读:
    MSDN2010安装及使用(MSDN Library)[转]
    单元测试那些事
    Nhibernate Profiler安装中的问题
    ztree的动态添加
    事件与委托
    linux ls dir
    学习技术资料的思路
    linux目录结构
    是否需要深入了解java平台
    工作中心的改变
  • 原文地址:https://www.cnblogs.com/dk2557/p/12807000.html
Copyright © 2011-2022 走看看