【发布时间】:2017-06-06 08:05:27
【问题描述】:
我有这些表:
任务组表
id name
1 cooking
2 baking
任务状态表
id name
1 open
2 done?
3 completed
4 re-open
5 suspend
任务表
project_id task_group_id task_status_id task_name
1 1 1 cooking martabak
1 1 2 cooking sate kambing
1 1 3 cooking nasi uduk
1 1 4 cooking nasi goreng
1 1 1 cooking martabak telor
1 1 2 cooking sate ayam
1 1 5 cooking nasi tutug oncom
1 1 5 cooking nasi pera
1 2 1 bake nastar
1 2 2 bake bolu pisang
1 2 3 bake bika ambon
1 2 5 bake bolu kukus
1 2 3 bake cheese stik
1 2 1 bake bolu ketan
1 2 5 bake papais
1 2 1 bake boled
我想要的结果是这样的:
project task_group task_status number
Restaurant Cooking Completed 1
Restaurant Cooking Done? 2
Restaurant Cooking Open 2
Restaurant Cooking Re-open 1
Restaurant Baking Completed 2
Restaurant Baking Done? 1
Restaurant Baking Open 3
Restaurant Baking Re-open 0
排除任务状态“暂停”
我尝试使用带有 where 子句 task_status.name in ('open', 'done?', 'completed', 're-open') 的子查询将任务表与任务状态表交叉连接,但我不能获得正确的计数聚合
【问题讨论】:
-
只需要按第一个表名和第二个表名分组
-
我试过了,但是计数结果不对...我确定我错过了加入的链接,但我不知道我如何加入它...