我有两个表,“问题”:问题列表,“QResults”用户对这些问题的结果。在再次询问之前,这些问题会在几小时内超时。
Table: Questions
ID
Timeout - The amount of time before asking the question again
Table: Results
ID
Created (timestamp) - When this record was added.
Questions_ID - A FK to the Question table
示例数据
Table: Questions
ID | Timeout (hrs)
--------------
1 | 1
8 | 6
15 | 1
55 | 1
Table: QResults
ID | Created | Q_ID
-------------------------------
1 | Jan 24, 2012 00:00 | 1
2 | Jan 24, 2012 06:05 | 15
3 | Jan 24, 2012 02:00 | 8
4 | Jan 24, 2012 01:00 | 1
5 | Jan 24, 2012 02:00 | 1
我正在寻找的是一个查询,它将根据上次回答问题的时间 + 超时对问题进行排序。如果问题从未得到回答,则应将其推到列表顶部。
例如,如果查询是在上述数据上运行的,它将产生以下数据集。
The result of the query I am looking for.
ID | timeout + created aka eligible
-------------------------------
55 | Jan 01, 1970 01:00 *(1) See note below*
1 | Jan 24, 2012 03:00 *(2) See note below*
8 | Jan 24, 2012 07:05
15 | Jan 24, 2012 08:00
*注意:(1) id=55 的日期无关紧要,只要它首先出现即可。因为目前没有它的 QResults。(2) 这具有 3hr 的值,因为它使用最新的答案创建时间 + 超时。
让我换一种说法。我正在寻找一个值最低的问题(最后一次询问+超时)。如果问题已被回答 3 次,则应使用最新的问题回答时间 + 超时作为合格值。我希望这是有道理的。