How could I reuse sub queries?

Tuesday, 8 August 2017 · 1 message
D
donaldjohn8 Aug 2017 03:23 #
Hi, everyone: Here is my query that finds the distinct value and counts them, you can see that I used the same sub query twice, first for finding the distinct values, second for count the distinct values, is there a way that I can cache the sub query result and reuse it somewhere else? I think it will run faster in that way.

⚡Generated with XQuery