MySQL中标签的用法

MySQL中标签的用法

先给大家来个SQL语句:

choose (when,otherwize) ,相当于java 语言中的 switch ,与 jstl 中 的 choose 很类似。

SELECT att.address, m.id, m.sex AS sex_type, m.nickname, m.focus_num, m.following_num, m.consulation_num, m.user_type, (select count(*) from alq_member_follow mf where m.id=mf.member_id and #{login_member_id}=mf.member_following_id and (mf.is_delete=0 or mf.is_delete is null)) as isFocus



0 as isFocus


FROM alq_member m
LEFT JOIN alq_attachment att ON att.id = m.logo_attachment_id
WHERE m.id=#{member_id}

这里面有 的用法,记录一下,choose (when, otherwise)标签

有时候我们并不想应用所有的条件,而只是想从多个选项中选择一个。而使用if标签时,只要test中的表达式为 true,就会执行 if 标签中的条件。MyBatis 提供了 choose 元素。if标签是与(and)的关系,而 choose 是或(or)的关系。

choose标签是按顺序判断其内部when标签中的test条件出否成立,如果有一个成立,则 choose 结束。当 choose 中所有 when 的条件都不满则时,则执行 otherwise 中的sql。类似于Java 的 switch 语句,choose 为 switch,when 为 case,otherwise 则为 default。

这样就很容易看懂了

你可能感兴趣的:(MySQL的标签)