首页 > 代码库 > mysql伪列

mysql伪列

 
 
<!-- NOTE:internal_name_trim使用的是伪列,而不是数据库返回的数据 -->
<select id="listByStoreIdAndPartsNoTrimAndBrandName" resultMap="productMap"> SELECT product_id, internal_name_trim FROM ( <foreach collection="productQuerys" item="productQuery" separator="UNION ALL" index="index"> (SELECT product_id, @myInternalName#{index} as internal_name_trim FROM product,(SELECT @myInternalName#{index}:= #{productQuery.internalNameTrim}) r WHERE product_store_id = #{productStoreId} AND partsno_trim = #{productQuery.partsNoTrim} AND brand_name = #{productQuery.brandName} LIMIT 1) </foreach> ) p </select>

 

 
 
注意:
1、limit 1 结尾后,一定要加括号,否则变成一条数据
2、使用伪列的名称不能一样,否则都以最后那条数据为准

mysql伪列