MySQL case when 用法

@Query(value="SELECT ca.cuser_question_id as cuserQuestionId, ca.id AS id, ca.answer_content AS answerContent, ca.create_time AS createTime, ca.laud AS laud,c.head_img as headImg, CASE WHEN ca.cuser_id = 'admin' THEN '商家回复' ELSE c.surname END 'surname' FROM cuser_answer ca "
+ "LEFT JOIN cuser c ON ca.cuser_id = c.id WHERE ca.cuser_question_id IN (:id) AND is_delete = 0 ORDER BY ca.laud DESC",nativeQuery = true)
List<Map<String, Object>> findAllQuery(@Param("id")List<String> idStr);

 

    1. 简单函数
      CASE [col_name] WHEN [value1] THEN [result1]…ELSE [default] END
    2. 搜索函数
      CASE WHEN [expr] THEN [result1]…ELSE [default] END

https://blog.csdn.net/qq_30038111/article/details/79611167

posted @ 2018-11-27 15:26  全栈冲鸭!  阅读(417)  评论(0编辑  收藏  举报