order by union 应用实例 mssql
2009-02-25 16:46
183 查看
order by union 应用实例 mssql跨库查询 分页问题烦了我一阵子了。找不到不影响速度的方法,主要原因是 UNION 与ORDER BY写在一起报错。因为order by不能直接出现在union的子句中,试着将它写在子句的子句中。于是问题解决了。至今不 知道SQL为什么不能把order by 写在union了句中。报错代码如下:
select '加密锁' as xxmc ,ssh from a709.dbo.ts_gcbunion all select '测试加密锁' as xxmc ,ssh from a710.dbo.ts_gcbunion all select '金思维演示第三图书馆' as xxmc ,ssh from jswlibs1.dbo.ts_gcb代码如下:SELECT * FROM (SELECT TOP 5 * FROM (SELECT TOP 40 * from (select '加密锁' as xxmc ,ssh from a709.dbo.ts_gcbunion all select '测试加密锁' as xxmc ,ssh from a710.dbo.ts_gcbunion all select '金思维演示第三图书馆' as xxmc ,ssh from jswlibs1.dbo.ts_gcb) as tempdb ORDER BY "ssh" desc) AS inner_tbl ORDER BY "ssh" ASC) AS outer_tbl ORDER BY "ssh" desc
相关文章推荐
- order by union 应用实例 mssql
- MySQL错误:ERROR 1221 (HY000): Incorrect usage of UNION and ORDER BY
- ORACLE union order by
- MSSQL 分组后取每组第一条(group by order by)
- 平面四参数转换和C#中的应用实例(By Kiseigo)
- Oracle中row_number() over(partition by a order b asc,c desc)的应用
- MySQL order by性能优化方法实例
- Sql UNION ALL 应用实例(Postgres数据库)
- 'union all' two select sentences contain 'order by'
- MYSQL之union和order by分析([Err] 1221 - Incorrect usage of UNION and ORDER BY)
- oracle-union order by rownum排序与取数
- mysql order by 优化 |order by 索引的应用
- MySQL order by性能优化方法实例
- mysql 5.7.15 union order by 子查询排序不生效
- 再谈 UNION ALL 和 ORDER BY NEWID 一起使用
- mysql union order by 分别排序问题
- [软件发布]:Java的数据库应用实例——汽车销售管理系统(JDBC+MSSQL)
- oracle查询语句中select from where group by having order by的解释与应用
- MSSQL 分组后取每组第一条(group by order by)
- T-SQL查询: TOP N [PERCENT] WITH TIES ORDER BY 顺序排序实例