sql server 解决union all之后 order by失效的问题
来源:互联网 发布:时代网络大厦 美食 编辑:程序博客网 时间:2024/05/02 00:14
注意关键点在TOP 99.999999 PERCENT
SELECT * FROM ( SELECT TOP 99.999999 PERCENT t.CallDate, t.userid, t.GroupName, t.AgentNum, t.username, t.duration, t.connectNumber, t.connectOrderNumber, t.callnumber, t.CallOrderNumber, t.ConnectionRate, t.OnlinSumbitNumber, t.connectsuccessRate, t.InputOrderNumber, t.InputOrderRate, t.SuccessOrderNumber, t.SuccessRate, t.FirstCallNumber, t.TrackNumber FROM @tab AS t WHERE t.userid IS NOT NULL ORDER BY t.CallDate ASC , CASE WHEN @OrderType=101 THEN t.duration END ASC , CASE WHEN @OrderType=102 THEN t.duration END DESC , CASE WHEN @OrderType=111 THEN t.connectNumber END ASC , CASE WHEN @OrderType=112 THEN t.connectNumber END DESC , CASE WHEN @OrderType=121 THEN t.ConnectionRate END ASC , CASE WHEN @OrderType=122 THEN t.ConnectionRate END DESC , CASE WHEN @OrderType=131 THEN t.connectsuccessRate END ASC , CASE WHEN @OrderType=132 THEN t.connectsuccessRate END DESC , CASE WHEN @OrderType=141 THEN t.InputOrderNumber END ASC , CASE WHEN @OrderType=142 THEN t.InputOrderNumber END DESC , CASE WHEN @OrderType=151 THEN t.InputOrderRate END ASC , CASE WHEN @OrderType=152 THEN t.InputOrderRate END DESC , CASE WHEN @OrderType=161 THEN t.SuccessOrderNumber END ASC , CASE WHEN @OrderType=162 THEN t.SuccessOrderNumber END DESC , CASE WHEN @OrderType=171 THEN t.SuccessRate END ASC , CASE WHEN @OrderType=172 THEN t.SuccessRate END DESC , CASE WHEN @OrderType=181 THEN t.FirstCallNumber END ASC , CASE WHEN @OrderType=182 THEN t.FirstCallNumber END DESC, CASE WHEN @OrderType=191 THEN t.TrackNumber END ASC , CASE WHEN @OrderType=192 THEN t.TrackNumber END DESC ) AS tt UNION ALL SELECT * FROM ( SELECT TOP 99.999999 PERCENT t.CallDate, t.userid, t.GroupName, t.AgentNum, t.username, t.duration, t.connectNumber, t.connectOrderNumber, t.callnumber, t.CallOrderNumber, CASE WHEN t.CallDate=N'合计' then null ELSE t.ConnectionRate end as ConnectionRate, t.OnlinSumbitNumber, CASE WHEN t.CallDate=N'合计' then null ELSE t.connectsuccessRate end as connectsuccessRate, t.InputOrderNumber, CASE WHEN t.CallDate=N'合计' then null ELSE t.InputOrderRate end as InputOrderRate, t.SuccessOrderNumber, CASE WHEN t.CallDate=N'合计' then null ELSE t.SuccessRate end as SuccessRate, t.FirstCallNumber, t.TrackNumber FROM @tab AS t WHERE t.userid IS NULL ORDER BY t.CallDate ASC ) AS v
0 0
- sql server 解决union all之后 order by失效的问题
- UNION ALL ORDER BY的问题
- 解决SQL Server查询中使用Union或Union All后Order by排序无效的bug(好神奇啊!!)
- SQL Union和SQL Union All两者用法区别效率以及与order by 和 group by配合问题
- union 或者 union all 与 order by 的联合使用
- oracle order by 和union all(union)的使用
- SQL数据库的order by排序失效问题
- union与union all与order by
- 【SQL】两个带order by查询进行union all报ORA-00933错误的解决方法
- 使用group by分组之后子查询的order by排序失效的问题
- MySQL 之union all 与 order by 同时出现问题
- SQL语句加入order by 子句之后的效率问题
- UNION ALL 和 Order by 同用
- SQL Server Order by在union子句不可直接使用的原因
- SQL Union 与Order By
- SQL Server中Union, Union All与TOP关键字同时使用的问题
- 九.Sql server中union, union all 的用法
- SQL Server函数----Union与Union All的区别
- Postman工具
- iOS 搜索框
- 分区表的导入导出 expdp&impdp Oracle 11.2.0.4
- SQL 查尋(分组/group by/count/sum/avg/max/min/null/having/top/over) 排序(rwo_number/rank/dense_raenk/ntile)
- 原码, 反码, 补码 详解
- sql server 解决union all之后 order by失效的问题
- heartbeat 高可用工具
- vim编辑的文档出现中文乱码
- 浅谈Android线程池封装
- 学习Android从0开始之背景篇-Android系统介绍
- android基础学习之Service(一)
- Windows Socket 编程_ 简单的服务器/客户端程序
- 66.第三方类FMDB(SQL管理数据库)
- 计算机网络——传输层