您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: