mybatis联合查询使用union,limit--order by不起作用
2017-11-09 10:50
591 查看
<select id="selectUnionData" resultMap="YszbResultMap" parameterType="java.util.List" > select total.* from ( select '漂流浮标' as type,PLFBQZH as qzh,GCRQSJ as gcrqsj,QW as qw,QY as qy,HW as hw,HY as hy,FS as fs,FX as fx from nt_plfbyssjzb <where> <if test="dtBegin!=null and dtBegin !=''"> and GCRQSJ >= #{dtBegin} </if> <if test="dtEnd!=null and dtEnd !=''"> and GCRQSJ <= #{dtEnd} </if> and PLFBQZH in <foreach item="item" index="listPlfbqzh" collection="listPlfbqzh" open="(" separator="," close=")"> #{item} </foreach> </where> union select '锚定浮标' as type,ZTH as qzh,YS01GCSJ as gcrqsj,YS03HBWD as qw,null as qy ,null as hw,YS08HSYD as hy,null as fs,null as fx from nt_hyqxyssjb <where> <if test="dtBegin!=null and dtBegin !=''"> and YS01GCSJ >= #{dtBegin} </if> <if test="dtEnd!=null and dtEnd !=''"> and YS01GCSJ <= #{dtEnd} </if> and ZTH in <foreach item="item" index="listMdfbqzh" collection="listMdfbqzh" open="(" separator="," close=")"> #{item} </foreach> </where> ) total <if test="strCol!=null and strCol !=''"> ORDER BY ${strCol} ${strSort} </if> LIMIT #{nStart}, #{nLength} </select>
一开始通过ORDER BY #{strCol} #{strSort} 来接收参数,但是查询的结果并没有排序,后来想到之前查询问题时有看到,#{strCol} #{strSort}接收的参数是带引号的,这边就换了${strCol}
${strSort} 试了一下,结果可以了。
相关文章推荐
- Mysql联合查询UNION和Order by同时使用报错问题的解决办法
- Mysql联合查询UNION和Order by同时使用报错问题的解决办法
- Mysql联合查询UNION和UNION ALL的使用介绍
- Mysql联合查询union和union all的使用介绍
- mysql两个字段相同的表联合查询(union的使用)
- Mysql联合查询UNION和UNION ALL的使用介绍
- 如何联合使用Union和Order by
- mybatis 使用 and和or联合查询
- MySQL联合查询,order by与LIMIT
- mysql同时使用order by和limit查询时的一个严重隐患 -- 丢失数据
- Mysql联合查询UNION和UNION ALL的使用介
- MySQL数据分页查询---limit、order by的使用
- mybatis example 使用AND 和OR 联合查询
- mybatis 使用 and和or联合查询
- 一个关于 联合查询union 和排序order by 的例子
- GROUP BY 和 ORDER BY 子句联合使用组合查询
- Mysql联合查询UNION和UNION ALL的使用介绍
- 【转】Mysql联合查询union和union all的使用介绍
- 使用UNION查询时,同时使用TOP 与ORDER BY遇到的问题
- 数据库中使用order by 和limit查询变慢解决办法