问题
As this doc said, "You currently cannot use GROUP BY with an ORDER BY clause but this is planned". But we do need to group by one field and order by another field. Is there a way to do it?
回答1:
According to my research, i'm afraid that there is no such direct official way to use GROUP BY with ORDER BY since the statement you mentioned in your question:
The GROUP BY clause must be after the SELECT, FROM, and WHERE clause and before the OFFSET LIMIT clause. You currently cannot use GROUP BY with an ORDER BY clause but this is planned.
You could submit your feedback to push the progress of this feature.
If your need is urgent,i would suggest you :
- a:sort the date after group by.Such as ARRAY.SORT() method in .net code.
- b:Or you could group by the data with this package(which is built on Stored Procedure in cosmos db) after order by.
来源:https://stackoverflow.com/questions/59185057/how-to-group-by-and-order-by-in-cosmos-db