mysql union 连用 order by 的限制条件
来源:互联网 发布:淘宝老七配件可信吗 编辑:程序博客网 时间:2024/05/29 04:20
一般多个结果连接需要使用 union 或者 union all 。
前言 :
最近产品提出了一个需求 , 需要通过三重条件来过滤 , 体验非常不好 ,和产品沟通无果后准备在 SQL 中进行过滤处理 。
踩到的第一个坑 : union all 的子条件查询语句 和 order by 不兼容 、 所以要再 嵌套一个select语句来 order by 。
踩到的第二个坑 : 多个 union all 进行 order by 的话 , 并不能真正的实现排序 , sql server等可以通过 top来解决 , 但是 mysql 不支持 top , 所以这里我用 limit max_num来解决 。
踩到的第三个坑 : 当 union all 后 不可以再添加 where , 所以需要在 嵌套 中直接 where 解决 。 (这就导致代码的冗余 , 如果配合 mybatis 使用的话 ,同一个代码将会随着 union的次数增多而增多 )
最后副个简码供参考吧 :
阅读全文
1 0
- mysql union 连用 order by 的限制条件
- mysql 数据库中 WHERE / ORDER BY/GROUP BY/LIMIT 几个限制条件的排序
- group by 与order by 连用的问题
- MySQL的union和order by一起使用的问题
- [mysql]union中各自order by的问题
- Mysql中Union的子句不支持order by
- MySQL中union和order by一起使用的方法
- 关于union的order by
- mysql中的union和order by、limit
- Mysql union order by 总结一下
- mysql中的union和order by、limit
- MYSQL之union和order by分析([Err] 1221 - Incorrect usage of UNION and ORDER BY)
- UNION中ORDER By的使用
- UNION ALL ORDER BY的问题
- union中的order by的应用
- UNION中ORDER By的使用
- union中order by的使用
- UNION中ORDER By的使用
- h5 17
- [k8s]k8s rbac语法
- 5.16题解报告
- hibernate spring springMVC常用注解
- Java1
- mysql union 连用 order by 的限制条件
- java 2
- oracle中 to_date() 如何取得毫秒
- mui和holle H5开发注意事项
- C++ new 和 delete 的那些事
- hdu 3001 Travelling (TSP问题,状压dp)
- java3
- 零散的汇编知识整理
- java 4