我有我想简化查询:MySQL - 如何简化这个查询?
select
sequence,
1 added
from scoredtable
where score_timestamp=1292239056000
and sequence
not in (select sequence from scoredtable where score_timestamp=1292238452000)
union
select
sequence,
0 added
from scoredtable
where score_timestamp=1292238452000
and sequence
not in (select sequence from scoredtable where score_timestamp=1292239056000);
任何想法?基本上我想从同一个表中提取两个时间戳值之间不同的序列。用一个“添加”的列来表示一行是新的还是一行已被删除。
源表:
score_timestamp sequence
1292239056000 0
1292239056000 1
1292239056000 2
1292238452000 1
1292238452000 2
1292238452000 3
(2行)(1292239056000,1292238452000) 查询结果之间示例:
sequence added
3 1
0 0
之间实施例(1292238452000,1292239056000) 查询结果(2行) :
sequence added
0 1
3 0
(129 2239056000,1292239056000) 查询结果(0行):
sequence added
+1彼得,我错过/搞砸了我的理解:) – 2010-12-13 12:53:33
太棒了!非常感谢! – 2010-12-13 13:08:29
糟糕!这不是同一个查询!我添加了更多的例子,这不满意这个查询:(例如,当与相同的时间戳比较或比较逆向顺序(我想比较较低的时间戳也)... – 2010-12-13 14:01:30