查询D列的returns值,但是B列不能有两个值都写了"G",怎么办?

The query returns values from column D, but there cannot be two values that have written "G" in column B, how to proceed?

在这个页面(Presence)上是Query,问题中说:

=QUERY(D4:H, "select D order by H desc limit 11", 0)

此页面(姓名和位置)上已有球员的 ID 和位置:

按照规定,一个队只能有一个守门员,所以我在定义11名球员时需要查询,如果其中有超过1个守门员(G),则守门员下面的守门员列表需要离开才能添加。 Query

创建的列表中的下一位玩家

Link To Spreadsheet

尝试:

=ARRAYFORMULA(QUERY({SORT({D4:D, H4:H}, 2, 0), 
       IF(IFERROR(VLOOKUP(INDEX(SORT({D4:D, H4:H}, 2, 0),,1), 'Name And Position'!A4:B, 2, 0))="G", 
 COUNTIFS(IFERROR(VLOOKUP(INDEX(SORT({D4:D, H4:H}, 2, 0),,1), 'Name And Position'!A4:B, 2, 0)), 
          IFERROR(VLOOKUP(INDEX(SORT({D4:D, H4:H}, 2, 0),,1), 'Name And Position'!A4:B, 2, 0)), 
          ROW(K4:K), "<="&ROW(K4:K)), 1)}, 
 "select Col1 where Col3 = 1 order by Col2 desc limit 11", 0))