sql if

格式:IF(Condition,A,B)

意义:当Condition为TRUE时,返回A;当Condition为FALSE时,返回B。


例子

   select A.student_id,sw,ty from
  
  (select student_id,num as sw from score left join course on score.course_id = course.cid where course.cname =  '生物' ) as A
  
         left join
  
(select student_id,num  as ty from score left join course on score.course_id = course.cid where course.cname =  '体育' ) as B
  
   on A.student_id = B.student_id where sw >  if(isnull(ty),0,ty);

如果isnull(true)为true时,返回  sw>0  否则 返回  sw> ty;

猜你喜欢

转载自blog.csdn.net/lunsunhuan1825/article/details/72918706