开发者

Doctrine 2 DQL: Can I combine these queries into 1

I am trying to combine these queries into 1

# Get completed todos
SELECT COUNT(t.id) from Application\Models\Todos t 
WHERE t.parent IS NULL 
AND t.todoList.project = :proj
AND t.completedOn IS NOT NULL

# Get total todos
SELECT COUNT(t.id) from Application\Models\Todos t
WHERE t.parent IS NULL 
AND t.todoList.project = :proj
  • A Project have Lists
  • A List have Todos
  • A Todo can have 1 level of children todo - In my queries, I was querying for top level todos
  • A Todo have completedOn, dueOn

In another function, I want to get

  • total number of tasks belo开发者_StackOverflownging to you & the project
  • total number of completed tasks belonging to you & the project
  • total number of incompleted tasks due today belonging to you & the project

Do I need to do it in separate queries?


If you had a flag INT completed 1/0 then yes, using a SUM and a COUNT, but in this case i dont think its possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜