1.前景
之前用oracle数据库做了一个项目,其中的分页模块是用rownum去写的,而现在数据库换成了mysql,分页也换成了limit,却发生了如下的事:
<select id="findEmpCounts" parameterType="java.util.Map" resultType="java.lang.Integer">
select count(1)
from (
select e.empno, e.ename, e.job, e.sal, e.comm, d.deptno, d.dname
from t_emp e
left join t_dept d on e.deptno = d.deptno
<where>
1=1
<if test='(ename != null) and (ename != "")'> and ename like '%'||#
{ename}||'%'</if>
<if test='(job != null) and (job != "")'> and job = #{job}</if>
<if test='sal > 0'> and sal >= #{sal}</if>
<if test='comm > 0'> and comm >= #{comm}</if>
<if test='(dept.deptno > 0)'> and d.deptno = #{dept.deptno}</if>
</where >
order by e.empno
)
</select>
2.问题解决
首先看报错信息:Every derived table must have its own alias
(英文不好)每个派生表都必须有自己的别名
可以看到我们的派生表并没有起别名,所以给派生表起个别名就好啦
oracle并没有这样的强制,而mysql有。
遇到问题记录一下。