sql中if的用法

   UPDATE micro_target t JOIN (
      SELECT sum(if (type = 1,1,0)) good,sum(if (type = 0,1,0)) soso,sum(if (type = -1,1,0)) bad
      FROM micro_target_comments
      WHERE target_id = #{targetId}
      ) tc
   SET comments_good_count = good,
   comments_soso_count = soso,
   comments_bad_count = bad
   WHERE t.target_id = #{targetId}
 

猜你喜欢

转载自yangjayup.iteye.com/blog/1672629