我有一个表活动,其字段如下
user_id
role_id
cost
inserted_at
updated_at
deleted_at
所以使用ecto查询我写了一个这样的查询
from t in activity, where: t.id == ^id, group_by: [t.user_id, t.role_id], select: %{inserted_at: t.inserted_at}
因为我不能在不使用聚合函数的情况下使用 select。所以我需要的是我需要选择为insert_at 字段插入的最后一个元素,并且不能在此使用聚合。我有哪些选择?
我怎样才能做到这一点?
group_by 还有其他选择吗,我可以达到与 group_by 相同的效果