Query to another query

Hi,
I am trying to calculate the handicap as is calcultated in golf, so, i am trying to get the average of the best 5 scores considering the last 10 games. What i thought is query for the last 10 games and then query the result for the best 5 scores, the question is, How can i query a query variable?, i did the code to get the first query, but i don’t know how to do the second query.

import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
let userEmail
let sel_u10
let sel_m5
wixUsers.currentUser.getEmail()
.then( (email) => {
userEmail = email
wixData.query( “HistoriaSki” )
.eq( “title” ,userEmail)
.descending( “newField” )
.limit( 10 )
.find()
.then( (results) => {
if (results.items.length > 0 ) {
sel_u10=results;
} else {
}
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} )
});

Hello.

Try to use a for or while loop on the results.items array and perform a calculation on the first 5 items since the array is already sorted in descending order.

Good luck!