union all和order by一起使用出问题
2010-05-21 13:49
483 查看
select * from (select * from (select zxbz,count(*)rs from dc_jhmy where 1=1 group by zxbz order by rs desc
union all
select 'hj' as zxbz,count(*)rs from dc_jhmy where 1=1)where rownum <= 100
SQL语句如上,我想实现除最后的union all 之前所有的记录先排序,然后在加上最后一条记录,可是 order by rs desc
放在现在的位置报错,命令未正确结束。
解决方法如下:利用临时表
select * from (select * from (select zxbz,count(*)rs from dc_jhmy where 1=1 group by zxbz order by rs desc)
union all
select 'hj' as zxbz,count(*)rs from dc_jhmy where 1=1)where rownum <= 100
union all
select 'hj' as zxbz,count(*)rs from dc_jhmy where 1=1)where rownum <= 100
SQL语句如上,我想实现除最后的union all 之前所有的记录先排序,然后在加上最后一条记录,可是 order by rs desc
放在现在的位置报错,命令未正确结束。
解决方法如下:利用临时表
select * from (select * from (select zxbz,count(*)rs from dc_jhmy where 1=1 group by zxbz order by rs desc)
union all
select 'hj' as zxbz,count(*)rs from dc_jhmy where 1=1)where rownum <= 100
相关文章推荐
- oracle union all和order by一起使用
- Oracle union all和order by一起使用
- MySQL的union和order by一起使用的问题
- oracle union all和order by一起使用
- Oracle union all和order by一起使用
- 关于union all中使用多个order by 子句引起的问题
- Oracle union all和order by一起使用
- MySQL中union和order by一起使用的方法
- UNION/UNION ALL和order by 连接使用
- Mysql联合查询UNION和Order by同时使用报错问题的解决办法
- 使用UNION查询时,同时使用TOP 与ORDER BY遇到的问题
- union 和order by 连接使用报错的问题
- Mysql联合查询UNION和Order by同时使用报错问题的解决办法
- SQL 语句中union all和order by同时使用
- 解决SQL Server查询中使用Union或Union All后Order by排序无效的bug(好神奇啊!!)
- 再谈 UNION ALL 和 ORDER BY NEWID 一起使用
- MySQL中union和order by一起使用
- 使用SELECT赋值时再用ORDER BY排序所产生的问题
- UNION中ORDER By的使用
- For all entries使用中注意的问题