I have the following question to answer:
For each tag, retrieve the 10 to-dos with quickest completion time (i.e. the time between the creation and the completion of the to-do)
Select *
From ToDoItem, Tag, ItemTag
Where
time between CreationDate and
CompletionDate is ASC AND
Tag.Id = ItemTag.ToDoId AND
ItemTag.TagId = ToDoItem.Id
Limit 10
creationdate
CompletionDate
2 issues with your query:
You need to use datediff()
function to get the time between.
Ordering the results ahould be done with order by
statement, not in the where part.
Select *
From ToDoItem, Tag, ItemTag
Where
Tag.Id = ItemTag.ToDoId AND
ItemTag.TagId = ToDoItem.Id
Order by datediff(completiontime, creationtime) asc
Limit 10