问题
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