mysql where条件中的判断语句

mysql where条件中的判断语句 

<if test="categoryId != null">
AND CASE 1 WHEN "Y"=(SELECT is_open from category as oca where oca.category_id=#{categoryId,jdbcType=VARCHAR}) 
THEN (cat.category_id = #{categoryId,jdbcType=VARCHAR} OR cat.parent_id = #{categoryId,jdbcType=VARCHAR}) 
ELSE (cat.category_id = #{categoryId,jdbcType=VARCHAR}) 
END
</if>

mybatis的配置文件:

	<!-- 根据条件分页查询媒体文件信息(用于栏目专题)  -->
	<select id="selectMedias" parameterType="map" resultType="com.school.domain.MediaBean">
		SELECT c.course_id AS courseId, c.category_id AS categoryId, c.school_id AS schoolId,
			c.course_type AS courseType, c.title, c.subtitle,c.summary, c.keywords, c.objectives, c.audiences, c.requirements,
			c.cover_image AS coverImage, c.promo_video_id AS promoVideoId, c.promo_video_url AS promoVideoUrl,
			c.privacy, c.passwd, c.is_free AS isFree,c. price, c.validity, c.user_id AS userId, c.status,
			c.is_recommended AS isRecommended, c.date_recommended AS dateRecommended,c.is_recommended_cetagory AS isRecommendedCetagory,
			c.ce_date_recommended AS ceDateRecommended, c.index_order AS indexOrder,c.special_order AS specialOrder, c.date_added AS dateAdded, c.last_modified AS lastModified,
			c.published_start_millis AS publishedStartMillis, c.published_end_millis AS publishedEndMillis, c.duration,
			u.nickname, u.avatar, cat.name As categoryName
		FROM course AS c
		LEFT JOIN user AS u ON(c.user_id = u.user_id)
		LEFT JOIN category AS cat ON(cat.category_id = c.category_id)
		WHERE c.school_id="wxj" 
		<if test="categoryId != null">
			 AND CASE 1 WHEN "Y"=(SELECT is_open from category as oca where oca.category_id=#{categoryId,jdbcType=VARCHAR}) 
			 THEN (cat.category_id = #{categoryId,jdbcType=VARCHAR} OR cat.parent_id = #{categoryId,jdbcType=VARCHAR}) 
			 ELSE (cat.category_id = #{categoryId,jdbcType=VARCHAR}) 
			 END
		</if>
		<if test="courseType != null">
		    AND c.course_type=#{courseType,jdbcType=VARCHAR}
		</if>
		<if test="currTimeMillis != null">
		    <![CDATA[
		             AND c.published_start_millis <= ${currTimeMillis} AND c.published_end_millis >= ${currTimeMillis}
		    ]]>
		</if>
		<if test="orderByClause != null">
		    ORDER BY ${orderByClause}
		</if>
		<if test="limitClause != null">
		    LIMIT ${limitClause}
		</if>
	</select>


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值