<select id="selectDeptListByRoleId" resultType="Integer"> select d.dept_id from sys_dept d left join sys_role_dept rd on d.dept_id = rd.dept_id where rd.role_id = #{roleId} <if test="deptCheckStrictly"> and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId}) </if> order by d.parent_id, d.order_num </select>
时间: 2024-02-23 11:56:20 浏览: 15
这个是一个 MyBatis 的 XML 配置文件中的一段 SQL 查询语句,根据传入的 roleId 参数查询对应的部门信息。其中使用了 left join 连接了 sys_dept 和 sys_role_dept 两张表,并使用了 if 条件判断,如果传入的 deptCheckStrictly 参数为 true,则排除了部门的父级部门。最后按照部门的父级部门和排序号进行排序。
相关问题
<select id="selectExecuteSqlDetail" resultType="com.cvte.model.entity.ExecuteSqlDetail"> SELECT s.product_id, s.mybatis_id, s.sql_template, s.count, s.t_id, s.version, d.consume_time, d.s_id, d.total_score, d.create_time FROM sql_template s JOIN sql_plan_detail d ON s.t_id = d.template_id WHERE s.product_id = #{productId} <if test="mybatisId != null"> AND s.mybatis_id = #{mybatisId} </if> <if test="version != null"> AND s.version = #{version} </if> <if test="startTime != null and endTime != null"> AND d.create_time BETWEEN #{startTime} AND #{endTime} </if> <if test="minScore != 0.0"> and d.total_score > #{minScore} </if> <if test="maxScore != 0.0"> and #{maxScore} > d.total_score </if> ORDER BY d.total_score DESC </select>
这是一段 MyBatis 的 SQL 查询语句,查询的是一个名为 sql_template 和一个名为 sql_plan_detail 的表的一些字段。其中,sql_template 表中的 product_id, mybatis_id, sql_template, count, t_id, version 字段和 sql_plan_detail 表中的 consume_time, s_id, total_score, create_time 字段被查询出来。查询条件包括 product_id、mybatis_id、version、startTime、endTime、minScore 和 maxScore。如果 mybatis_id 不为空,则会加上一个额外的条件。如果 version 不为空,则也会加上一个额外的条件。如果 startTime 和 endTime 不为空,则加上一个时间范围的条件。如果 minScore 和 maxScore 不为 0,则分别加上一个总分数的最小值和最大值的条件。最后,结果按照 total_score 降序排序。
<select id="getProductFinalJujubePriceList" resultType="java.lang.Integer"> SELECT p.final_jujube_price FROM pms_product AS p WHERE p.id IN #{productIdList} </select>为什么报SQL语法异常
根据你提供的 SQL 代码,我注意到可能有两个问题导致 SQL 语法异常。
首先,你的 IN 子句使用了 #{productIdList},这看起来像是 MyBatis 或类似的持久化框架的占位符语法。然而,在原生的 SQL 语法中,IN 子句应该使用括号包裹参数,如下所示:
```sql
SELECT p.final_jujube_price
FROM pms_product AS p
WHERE p.id IN (1, 2, 3) -- 请替换为实际的产品 ID 列表
```
请确保你已将实际的产品 ID 列表替换到 IN 子句中。
第二个可能的问题是你的 SQL 语句缺少分号(;)作为结束符。尽管在某些数据库中分号是可选的,但在其他数据库中可能是必需的。请根据你使用的数据库的要求添加分号。
如果你已经修复了上述问题但仍然遇到 SQL 语法异常,请提供更多关于异常的详细信息,以便我能更好地帮助你解决问题。