我就過來了同樣的問題,最近。因此,這裏有一個解決方案,使用臨時表。其實,我提供了兩種解決方案。
溶液(A)標識使用子查詢(非常耗時的)後續log_action_link
# Very time-consuming
CREATE TEMPORARY TABLE tmp
(INDEX idlink_follow (idlink_follow))
SELECT idlink_va, time_spent_ref_action AS time_spent_action, idvisit, (
SELECT idlink_va FROM piwik_log_link_visit_action b
WHERE (a.idvisit = b.idvisit) AND (b.idlink_va < a.idlink_va)
ORDER BY idlink_va
LIMIT 1
) AS idlink_follow
FROM piwik_log_link_visit_action a
ORDER BY idvisit DESC, idlink_va DESC;
溶液(b)依賴於乾淨徹底piwik_log_link_visit_action
表。這通常是這種情況,但你永遠無法確定。
# Create table containing the time per action
# (requires a clean and complete piwik_log_link_visit_action)
CREATE TEMPORARY TABLE tmpA
SELECT idlink_va, time_spent_ref_action, idvisit
FROM piwik_log_link_visit_action
ORDER BY idvisit, idlink_va;
SELECT * FROM tmpA;
SET @lagID = NULL;
CREATE TEMPORARY TABLE tmp
(INDEX idlink_follow (idlink_follow))
SELECT @lagID AS idlink_follow, time_spent_ref_action AS time_spent_action, @lagID:=idlink_va AS idlink_va
FROM tmpA
ORDER BY idvisit, idlink_va;
DROP TEMPORARY TABLE tmpA;
基於臨時表,頁面時間可以訪問:
SELECT l.idvisit, t.time_spent_action, l.*
FROM piwik_log_link_visit_action l
LEFT JOIN tmp t ON (t.idlink_follow = l.idlink_va)
ORDER BY l.idvisit, l.server_time
心靈刪除臨時表。
DROP TEMPORARY TABLE tmp;
放在http://www.sqlfiddle.com的表與一些示例數據 –
下面是一些示例數據: http://www.sqlfiddle.com/#!9/62f235/3 – LarsVegas
你好雷蒙德,你認爲你有解決方案嗎? – LarsVegas