Mysql 是否继续查看?目前我正在编写一份报告,没有时间从转储恢复数据并重播更新。我会在几天内尝试一下,如果你的陈述正确,我会通知你。 UPDATE `timelog` t SET `location`=(SELECT location

Mysql 是否继续查看?目前我正在编写一份报告,没有时间从转储恢复数据并重播更新。我会在几天内尝试一下,如果你的陈述正确,我会通知你。 UPDATE `timelog` t SET `location`=(SELECT location ,mysql,sql,sql-update,subquery,Mysql,Sql,Sql Update,Subquery,是否继续查看?目前我正在编写一份报告,没有时间从转储恢复数据并重播更新。我会在几天内尝试一下,如果你的陈述正确,我会通知你。 UPDATE `timelog` t SET `location`=(SELECT location FROM timelog tl WHERE tl.end_ts=t.end_ts AND location != 'null' ORDER BY tl.log_id DESC


是否继续查看?目前我正在编写一份报告,没有时间从转储恢复数据并重播更新。我会在几天内尝试一下,如果你的陈述正确,我会通知你。
UPDATE `timelog` t
SET `location`=(SELECT location
                FROM timelog tl
                WHERE tl.end_ts=t.end_ts AND location != 'null'
                ORDER BY tl.log_id DESC
                LIMIT 0,1) -- Just to make sure that I get 1 or 0 results
WHERE end_ts > '2012-01-01 00:00:00' AND location = 'null';
CREATE OR REPLACE VIEW right_locations AS
SELECT l.*, t.end_ts, t.location, (SELECT location FROM timelog tl WHERE tl.end_ts=t.end_ts AND location != 'null' ORDER BY tl.log_id DESC LIMIT 0,1) AS "possible", t.end_location
FROM `log` l
JOIN timelog t ON t.log_id=l.log_id
WHERE l.action_id =7 AND l.ts > '2012-01-01 00:00:00'
ORDER BY end_location;

UPDATE timelog t
JOIN right_locations r ON r.log_id=t.log_id
SET t.location = r.possible
WHERE t.end_ts > '2012-01-01 00:00:00' AND t.location = 'null';
UPDATE timelog t
SET location = (
  select location from (
    SELECT tl.location
    FROM timelog tl
    WHERE tl.end_ts = t.end_ts AND tl.location != 'null'
    ORDER BY tl.log_id DESC
    LIMIT 1
 ) as x
WHERE 
  t.end_ts > '2012-01-01 00:00:00' AND 
  t.location = 'null';
create view timelogView
(
SELECT location
FROM timelog tl
WHERE tl.end_ts=t.end_ts AND location != 'null'
ORDER BY tl.log_id DESC
LIMIT 0,1
)

UPDATE `timelog` t
SET `location`=(SELECT location
                FROM timelogView tl) -- Just to make sure that I get 1 or 0 results
WHERE end_ts > '2012-01-01 00:00:00' AND location = 'null';
UPDATE timelog t1
INNER JOIN timelog t2
    ON t1.end_ts = t2.end_ts
    AND t2.location != 'null'
LEFT JOIN timelog t3
    ON t2.end_ts = t3.end_ts
    AND t3.location != 'null'
    AND t2.log_id < t3.log_id
SET t1.location = t2.location
WHERE t1.end_ts > '2012-01-01 00:00:00'
AND t1.location = 'null'
AND t3.log_id IS NULL;