Aproject
有很多tasks
。Atask
可以由多个 之一处理users
。例如:
Project Task By
------- -------- ------
P1 T1 U1
T2 U2
P2 T1 U3
T2 U4
T3 U5
P3 T1 U1
T2 U3
T3 U5
P4 T1 U1
T2 U3
如何查询用户处理的项目count of
中的最后一个任务?输出报告预计为:
Task By Count
---- ---- -----
T2 U2 1
T2 U3 1
T3 U5 2
更新:(对于 Deefours 的评论):这是我为计算最后一项任务所做的工作(但不确定如何获取By列):
self.find_by_sql('select task_id, count(task_id) as "count"
from (
select task_id
from (
select * from tasks order by created_at desc
)
tasks_sorted
group by project_id
)
latest_tasks
group by task_id;')