Let bindings can be used to define aliases for any sequence, for convenience.

For each incoming tuple, the expression in the let clause is evaluated to a sequence. A binding is added from this sequence to the let variable in each tuple. A tuple is hence produced for each incoming tuple.

for $x in collection("captains") let $century := $x.century group by $century let $number := count($x) where $number gt 1 return { "century" : $century, "count" : $number }

Note that it is perfectly fine to reuse a variable name and hide a variable binding.

for $x in collection("captains") let $century := $x.century group by $century let $number := count($x) let $number := count(distinct-values(for $series in $x.series return typeswitch($series) case array return $series() default return $series )) where $number gt 1 return { "century" : $century, "number of series" : $number }