Unknown column 'shelf.n_id' in 'field list'
时间: 2024-01-04 15:55:48 浏览: 140
This error message indicates that the column 'n_id' does not exist in the table 'shelf'. It could be a typo in the query or the column may have been renamed or deleted. Double-check the table structure and the query syntax to identify and correct the issue.
相关问题
请帮我解释下面这段代码 <select id="listByUser" resultType="com.yj.model.vo.EnrollByUserItemVO"> select cc.*, cc.course_start_time AS courseStartTimeMd, ub.id ubid, info.payment_status as payment_status, info.total_money as totalMoney, ccc.category_name, CASE WHEN cc.course_video is not null and cc.course_video != '' THEN 2 WHEN (SELECT count(1) FROM crs_course_class ccc2 WHERE cc.id = ccc2.course_id AND ccc2.data_flag = 1 AND ccc2.class_video IS NOT NULL and ccc2.class_video != '') > 0 THEN 2 ELSE 1 END AS courseType from user_course_enroll ub INNER JOIN crs_course cc ON ub.course_id = cc.id INNER JOIN crs_course_category ccc ON cc.course_category_id = ccc.id LEFT JOIN order_item item ON item.project_relevancy_id = ub.id LEFT JOIN order_info info ON item.info_id = info.id LEFT JOIN user_browse uu ON uu.user_id = ub.user_id and uu.course_id = ub.course_id and uu.data_flag = 1 where 1 = 1 <if test="(publicId != null and publicId != '' ) or ( userIds != null and userIds.size() != 0)"> and ( <if test="publicId != null and publicId != '' "> ub.public_id = #{publicId} </if> <if test="publicId != null and publicId != '' and userIds != null and userIds.size() != 0"> or ub.user_id IN <foreach collection="userIds" item="item" open="(" separator="," close=")" index="index"> #{item} </foreach> </if> <if test="(publicId == null or publicId == '') and userIds != null and userIds.size() != 0"> ub.user_id IN <foreach collection="userIds" item="item" open="(" separator="," close=")" index="index"> #{item} </foreach> </if> ) </if> <choose> <when test="query.paymentStateList != null and query.paymentStateList.size() != 0"> and ccc.data_flag = 1 </when> <otherwise> and ub.apply_type = 1 and ccc.data_flag = 1 and ub.data_flag = 1 and ub.verify_state = 1 and cc.data_flag = 1 </otherwise> </choose> <if test="query.shelfStatus !=null"> and cc.shelf_status = #{query.shelfStatus} </if> <if test="query.categoryId !=null and query.categoryId != ''"> and ccc.id = #{query.categoryId} </if> <if test="query.learnState !=null"> and uu.learn_state = #{query.learnState} and ccc.prelect_way = 1 </if> <if test="query.paymentStateList != null and query.paymentStateList.size() != 0"> AND ( info.payment_status IN <foreach collection="query.paymentStateList" item="item" open="(" separator="," close=")" index="index"> #{item} </foreach> ) </if> </select>
这是一个 MyBatis 的 SQL 查询语句,通过 id 属性指定查询语句的名称为 "listByUser",通过 resultType 指定查询结果映射到 com.yj.model.vo.EnrollByUserItemVO 类型的实例对象中。
查询语句主要是通过多个表的连接查询,得到用户选课信息的详细数据。其中包括课程信息、课程分类信息、用户选课信息、订单信息等。查询条件根据用户传入的参数动态生成。在条件中使用了 if 和 foreach 标签,根据不同的情况生成不同的查询条件。
除此之外,查询语句中还使用了 choose 标签,根据不同的条件生成不同的查询条件,相当于 Java 中的 switch 语句。
最后,查询语句中还使用了 CASE WHEN 语法,根据不同的条件返回不同的结果。在这个查询语句中,根据课程是否有视频,以及课程下是否有班次有视频,分别标记课程类型为 2 或 1。
SELECT DISTINCT layer_num FROM t_shelf_section WHERE layer_num = ( SELECT MAX( layer_num ) FROM t_shelf_section WHERE shelf_id = 13) and shelf_id = 13 这个转成mybatis xml文件写法
以下是将给定 SQL 查询转换为 MyBatis XML 文件的示例:
```xml
<select id="selectMaxLayerNumByShelfId" resultType="java.lang.Integer" parameterType="java.lang.Integer">
SELECT MAX(layer_num) FROM t_shelf_section WHERE shelf_id = #{shelfId}
</select>
<select id="selectLayerNumsByShelfIdAndMaxLayerNum" resultType="java.util.List" parameterType="java.util.Map">
SELECT DISTINCT layer_num FROM t_shelf_section WHERE layer_num = #{maxLayerNum} AND shelf_id = #{shelfId}
</select>
```
你可以在 Java 代码中定义一个 `Map` 参数,其中 `shelfId` 和 `maxLayerNum` 分别对应 SQL 查询中的参数 `#{shelfId}` 和 `#{maxLayerNum}`,并将其传递给 MyBatis 执行该查询。例如:
```java
Map<String, Object> params = new HashMap<>();
params.put("shelfId", 13);
params.put("maxLayerNum", sqlSession.selectOne("selectMaxLayerNumByShelfId", 13));
List<Integer> layerNums = sqlSession.selectList("selectLayerNumsByShelfIdAndMaxLayerNum", params);
```
阅读全文