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
本文讨论了SQL语句中使用Unionall前排序的技巧,并通过实例展示了如何利用临时表来解决命令未正确结束的问题,适用于数据库管理和查询优化。
1789

被折叠的 条评论
为什么被折叠?



