1

我对以下 SQL 查询 (MySQL) 有疑问:

SELECT CAST(LEFT(SUBSTR(STORE.VALUE, LOCATE('timestamp":', STORE.VALUE)+11),13) AS UNSIGNED) as starttime
FROM STORE
HAVING starttime <= MIN(starttime)+600000;

此查询返回 1 个值:1344543364317这是列 starttime 的最小值。

以下手动完成计算的查询返回更多值。

SELECT CAST(LEFT(SUBSTR(STORE.VALUE, LOCATE('timestamp":', STORE.VALUE)+11),13) AS UNSIGNED) as starttime
FROM STORE
HAVING starttime <= 1344543964317;

为什么这个查询返回更多的值?

编辑

关于数据的更多解释:不幸的是,大多数数据都毫无用处。基本上该表只包含两列:Key、Value。关键在这里并不重要。该值包含如下内容:{"changeset":"Z:1>6b|5+6b$Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http://j.mp/ep-lite\n","meta":{"author":"","timestamp":1344543364317,"atext":{"text":"Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http://j.mp/ep-lite\n\n","attribs":"|6+6c"}}}

所以我基本上只是提取时间戳值并将其显示为一个名为 starttime 的虚拟列。starttime 列的前 10 个值是

1344543364317
1344543365939
1344543366439
1344543366454
1344543368794
1344553433259
1344553434054
1344553499779
1344553500871
1344553502104
4

2 回答 2

3

您的值 1344543964317 远大于 4294967295,这是UNSIGNED整数的最大可能值。改为使用BIGINT

于 2013-02-25T11:18:03.827 回答
0

它不是很优雅,但我有一个解决方案。好像不能用startttime在等式右边,所以需要重做原来的计算。

SELECT CAST(LEFT(SUBSTR(VALUE, LOCATE('timestamp":', VALUE)+11),13) AS UNSIGNED) AS starttime
FROM STORE
HAVING starttime <= 
    (SELECT MIN(CAST(LEFT(SUBSTR(STORE.VALUE, LOCATE('timestamp":', STORE.VALUE)+11),13) AS UNSIGNED)) FROM STORE) + 60000
于 2013-02-25T11:48:36.177 回答