MySQL's ifnull function

Source: Internet
Author: User

The MySQL function has a useful function ifnull, which is in the form of ifnull (fielda,fieldb), meaning that when the field Fielda is null, it takes FIELDB, not NULL when the value of Fielda is taken .

This function works in conjunction with an external connection to serve as the IIF or NVL of Oracle:

The following code is for reference:

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) between '" +f Romdate+ "' 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 ();

MySQL's ifnull function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.