Hi Greg,
Can you please elaborate on your use case? Can you give an example for such a query?
In general, you have the HistoryService to query historical data. You can use methods like createHistoricProcessInstanceQuery to get a list of process instances that match certain criteria. If you need an aggregated value (e.g. the average duration), it would be inefficient to select all process instances first and calculate the value in your plugin's code. In addition, beginning with the last 7.5.0-alpha the history service has a method #createHistoricProcessInstanceReport to generate aggregated results. That API is currently limited to minimum, maximum, and average duration of process instances in an arbitrary time span. For anything else, I would use a custom query.
Cheers,
Thorben