我有两张桌子,任务和动作。 actions有两列,created_at和updated_at。任务有一个列started_at
我该怎么做
SELECT MAX( UNIX_TIMESTAMP( tasks.started_at ) ) AS started_at, action . *
FROM tasks, action
WHERE UNIX_TIMESTAMP( action.created_at ) > started_at
OR UNIX_TIMESTAMP( action.updated_at ) > started_at
尝试选择比MAX更多的created_at或updated_at的所有操作(tasks.started_at)
答案 0 :(得分:1)
SELECT * FROM actions
WHERE created_at>(SELECT MAX(started_at) FROM tasks) OR
updated_at>(SELECT MAX(started_at) FROM tasks)
不要担心性能,默认情况下MySQL应该缓存SELECT MAX(started_at) FROM tasks
值。如果您有其他配置,请将SQL_CACHE
添加到主查询:SELECT SQL_CACHE * FROM...