我的方案如下:
Table Persons
- id (primary key)
- name
Table Logs
- id (primary key)
- person_id (foreign key)
- datetime
- status
现在我想创建一个SQL查询以便检索:
此查询仅检索具有匹配关系的名称:
SELECT p.id, p.name, DATE_FORMAT(l.datetime,'%d-%m-%Y %H:%i:%s') AS datetime, l.status
FROM Persons p LEFT OUTER JOIN Logs l
ON p.id = l.person_id
WHERE l.id IN (SELECT id from Logs T1
INNER JOIN (SELECT MAX(id) AS Max_id FROM Logs
GROUP BY person_id
) T2
ON T1.id = T2.Max_id)
ORDER BY l.status, p.name";
如何在不与表日志关系的情况下获取名称?
答案 0 :(得分:0)
您可以使用LEFT JOIN:
function createMemoizedFunc() {
var memo;
function f() {
var value;
if (memo) { value = memo.cloneNode(); }
else {
var value = document.createElement("div");
value.innerHTML = "hello";
memo = value;
}
return value;
}
return f;
}
var create_node = createMemoizedFunc();