我只想在 derby 数据库中检索十条记录。我一直在寻找这样做的教程:
select * from (select ROW_NUMBER() OVER() AS rownum,name,effort from (select name, effort from
(select TBL_PROJECT_DETAIL.P_NAME as Name, sum(TBL_TIMESHEET.EFFORT) as effort from
TBL_TIMESHEET join tbl_project_detail on TBL_TIMESHEET.PROJECT_ID = TBL_PROJECT_DETAIL.ID group by TBL_PROJECT_DETAIL.P_NAME) as New)
as new2)
as new3
where rownum <= 10
我可以先使用 whererownum <= 10
最后将数据限制为 10,但问题是数据不是order by
首先使用子句排序的,所以我得到了 10 个随机数据。
当我order by
在数据之前给出rownum
:
select * from (select ROW_NUMBER() OVER() AS rownum,name,effort from
(select name, effort from
(select TBL_PROJECT_DETAIL.P_NAME as Name, sum(TBL_TIMESHEET.EFFORT) as effort from
TBL_TIMESHEET join tbl_project_detail on TBL_TIMESHEET.PROJECT_ID = TBL_PROJECT_DETAIL.ID group by TBL_PROJECT_DETAIL.P_NAME)
as New)
as new2 order by effot desc)
as new3 where rownum <=10
它给出了错误。再次将结果作为内表进行查询时,它就像不能group by
,但是对derby的要求是使用row_number。首先在内部添加 row_number 并在下一层中使用它。任何人都可以帮忙吗?德比不受支持限制。有什么其他方法可以让我先订购 10 条记录吗?