我想僅檢索10個記錄在德比數據庫中。我一直在尋找的教程這樣做:SQL爲限制記錄組在德比數據庫中
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
我可以用其中rownum <= 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
當你把結果作爲內部查詢再次查詢,但德比的要求是使用row_number。首先在內部添加row_number,並在下一層的哪裏使用它。任何人都可以幫忙?德比不支持限制。首先我可以先訂購10首唱片的其他方式?
可以給你完整的查詢 –