Reputation: 199
I have requirement to find max(date) from a list of dates using structured query. Below is the sample data
<Dates>
<Date>20200808</Date>
<Date>20200809</Date>
<Date>20200810</Date>
</Dates>
From the above sample data, i need to pick the result of 20200810
Upvotes: 0
Views: 274
Reputation: 7335
If the task is to get the maximum value from a single document, something like the following should work:
fn:max($doc/Dates/Date/xdmp:parse-yymmdd("yyyyMMdd", fn:string(.))
See https://docs.marklogic.com/xdmp:parse-yymmdd and https://docs.marklogic.com/fn:max
If the task is to get the maximum value from a set of documents, one approach is to create a TDE index that projects xs:date
values from the documents into an index and write an Optic query that uses op:max()
to get the maximum value from the index.
Hoping that helps,
Upvotes: 1