如何从选定数据中删除最后一行。我需要对数据进行排序并对其进行排序。但最后一行从未使用过。也许有人知道一个例子?
问问题
5878 次
4 回答
6
你可以试试这个
with t as (select 1 field from dual
union all
select 2 from dual)
select * from (
select count(*) over(order by field desc) cnt, t.* from t
)
where cnt != rownum
于 2012-12-14T08:24:44.543 回答
1
如果您的类似MySQL,请查看此问题:How to select all rows from a table EXCEPT the last one and see this code there
SELECT * FROM TABLE WHERE ID != (SELECT MAX(ID) FROM TABLE)
这里 "ID != (SELECT MAX(ID) FROM TABLE)" 这部分剪切了序列中编号最高的最后一行(为此,您必须声明一个整数字段(ID),它将是 auto_increment。该字段将给你MAX(ID)记录的最后一行的最大值)
于 2012-12-14T08:53:47.797 回答
1
假设您有一些查询返回一定数量的行,您可以使用 COUNT(*) OVER () 来找出它返回的行数。要消除最后一行,您必须将查询推送到子查询中并过滤 ROWNUM ...
select ...
from (select count(*) over () total_rows,
...
from ...
where ...
order by ...)
where rownum < total_rows
于 2012-12-15T21:48:44.507 回答
-1
试试这样
select * from table
where rowid<>(select max(rowid) from table);
或者
select * from table
minus
select * from table where rownum = (select count(*) from table)
于 2012-12-14T08:23:27.973 回答