0
因此,假设我有这个表4列:在同一查询中涉及到已经获取的成果在查询
id content parent timestamp
借此父列是指在表中的另一个条目的ID
我要做到以下几点:
从以下有序表中选择第50行:
for each row,
if(parent = 0){
add row to resultset, ordered by timestamp
}
else if (parent != 0){
if parent is in the list of rows already fetched so far by the query,
add row to resultset, ordered by the timestamp
otherwise, wait until the parent gets fetched by the query
(assuming it gets fetched at all since there we're only getting the first 50 rows)
}
这种排序逻辑有点复杂,我想知道是否可以在单个查询中使用MYSQL ORDER BY语句完成此操作,而无需使用子查询?也许我们可以设置和使用变量?但是,ORDER BY声明将如何实施?
我敢肯定,这是不可能的'订单'并且相当困难,即使子查询。从树结构中提取子树将具有相似的伪代码。而且,提取子树是一个难题。 – 2013-05-06 21:54:03
是一对一的父母孩子吗?它只有一个深度? – mconlin 2013-05-06 23:45:35