在无绑定操作中使用 MAX 和 MIN
Use MAX and MIN in Bindingless operations
所以我已经阅读了关于 Bindingless 操作的 ecto 文档。它们非常适合动态值。
from Post,
where: [category: "fresh and new"],
order_by: [desc: :published_at],
select: [:id, :title, :body]
所以我的问题是。有没有什么办法可以像这样在上面使用 max
或 min
:
select: max[:some_field]
我试过了,但没用。
如果有人建议任何方法如何使用它。
谢谢
Ecto 提供 Ecto.Query.API.max/1
绑定值。
对于无绑定操作,应该坚持Ecto.Query.API.fragment/1
:
fragment("max(?)", :some_field)
所以我已经阅读了关于 Bindingless 操作的 ecto 文档。它们非常适合动态值。
from Post,
where: [category: "fresh and new"],
order_by: [desc: :published_at],
select: [:id, :title, :body]
所以我的问题是。有没有什么办法可以像这样在上面使用 max
或 min
:
select: max[:some_field]
我试过了,但没用。
如果有人建议任何方法如何使用它。
谢谢
Ecto 提供 Ecto.Query.API.max/1
绑定值。
对于无绑定操作,应该坚持Ecto.Query.API.fragment/1
:
fragment("max(?)", :some_field)