PARTITION BY doesn't work in H2 db

℡╲_俬逩灬. 提交于 2019-12-07 08:58:48

问题


I'm using PARTITION BY clause to do sorting on the result. Details for using PARTITION BY is mentioned in this question Sql Order by on multiple column. It works fine when i run in Oracle. I'm using H2 db for my unit test cases. When i run the same query on H2 db, it doesn't work. Is it known issue in H2? Is there any alternate solution which can work in Oracle and H2 both.


回答1:


I don't think H2 supports window functions (aka analytic functions). However, you can do the query in the link using standard SQL:

SELECT t.*
FROM yourtable t join
     (select vendorname, max(incidentdate) as maxdate
      from yourtable yt
      group by vendorname
     ) vn
     on vn.vendorname = yt.vendorname
ORDER BY vn.maxDate DESC, t.VendorName ASC, t.IncidentDate DESC;

Although this should run in both environments, the over form probably performs better in SQL.



来源:https://stackoverflow.com/questions/16928714/partition-by-doesnt-work-in-h2-db

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!