zoukankan      html  css  js  c++  java
  • IFNULL函数

    MySQL函数里有一个很有用的函数IFNULL,它的形式是IFNULL(fieldA,fieldB),意义是当字段fieldA是NULL时取fieldB,不是NULL时取fieldA的值。

    这个函数与外连接配合使用时能起到Oracle的IIF或是NVL的作用:

    以下代码供参考:

            StringBuilder sb=new StringBuilder();
            sb.append("    select ");
            sb.append("           t1.fullName,IFNULL(t2.actualHour,0) as actualHour,t1.planhour,t1.annotatorId,t1.annotatorId,IFNULL(t2.actualHour,0)/t1.planhour as ratio");
            sb.append("    from ");
            sb.append("          XXshipTB  t1 ");
            sb.append("          left outer join (select userid,sum(hours) as actualHour from dayworkTB where (Date(date) between '"+fromDate+"' and '"+endDate+"') group by userid)  t2");
            sb.append("    on ");
            sb.append("           t1.annotatorId=t2.userid");
            sb.append("      and  abs(t2.actualHour-t1.planhour)>0.01");
            sb.append("    ORDER by ");
            sb.append("           ratio desc,t1.fullName asc");
            String sql=sb.toString();

  • 相关阅读:
    对象进行比较
    java中length,length(),size()区别
    引用数据类型、自定义类
    java方法
    学员信息管理系统案例
    商品库存管理查看增减
    引用数据类型Scanner,Random
    Cantor表巧妙的做法
    UVA 11292 The dragon of Loowater勇士斗恶龙 11729 突击战 Commando War
    期末,祝不挂
  • 原文地址:https://www.cnblogs.com/doudouxiaoye/p/5773623.html
Copyright © 2011-2022 走看看