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