我正在尝试运行以下查询:
tokens =
Ecto.assoc(struct, [:documents, :tokens])
|> distinct(false)
|> select([t], %{length: fragment("length(?)", t.verbatim)})
from(token in subquery(tokens),
group_by: token.length,
order_by: token.length,
select: %{length: token.length, frequency: count(token.length)}
)
|> Repo.all()
但这给我一个only one distinct expression is allowed in query
错误。
如何编写子查询,以便在这种情况下不会生成SELECT DISTINCT
?