Oracle NoSQL数据库中的BETWEEN和dates运算符,怎么办?
Operator BETWEEN and dates in Oracle NoSQL Database, how to do?
我想使用 BETWEEN 操作在 nosql 数据库中进行查询?我想做这样的事情:
SELECT * FROM table
WHERE column_timestamp BETWEEN '2021-01-01'
AND '2021-12-31'
如何在 NoSQL 数据库中执行此查询?支持 BETWEEN 吗?
在你的情况下,因为你的列似乎是时间戳,你需要将时间戳值转换为 TIMESTAMP 类型。然后您只需使用 <= 和 >= 运算符。
在查询仅提供时间的日期 w/o 时要小心。这是一个使用 <, <=, >=, >.
的测试用例
I've inserted 3 rows :
2021-12-01T00:00:00Z
2021-12-31T00:00:00Z
2021-12-31T23:59:59Z
SELECT * FROM TEST
where date > CAST("2021-12-01" as timestamp) and date < CAST("2021-12-31" as timestamp)
no rows selected
SELECT * FROM TEST
where date >= CAST("2021-12-01" as timestamp) and date <= CAST("2021-12-31" as timestamp)
2 rows : 2021-12-01T00:00:00Z and 2021-12-31T00:00:00Z
SELECT * FROM TEST
where date >= CAST("2021-12-01T00:00:00" as timestamp)and date <= CAST("2021-12-31T23:59:59" as timestamp)
3 rows : 2021-12-01T00:00:00Z , 2021-12-31T00:00:00Z and 2021-12-31T23:59:59Z
SELECT * FROM TEST
where date >= CAST("2021-12-01" as timestamp) and date < CAST("2022-01-01" as timestamp)
3 rows : 2021-12-01T00:00:00Z , 2021-12-31T00:00:00Z and 2021-12-31T23:59:59Z
我想使用 BETWEEN 操作在 nosql 数据库中进行查询?我想做这样的事情:
SELECT * FROM table
WHERE column_timestamp BETWEEN '2021-01-01'
AND '2021-12-31'
如何在 NoSQL 数据库中执行此查询?支持 BETWEEN 吗?
在你的情况下,因为你的列似乎是时间戳,你需要将时间戳值转换为 TIMESTAMP 类型。然后您只需使用 <= 和 >= 运算符。
在查询仅提供时间的日期 w/o 时要小心。这是一个使用 <, <=, >=, >.
的测试用例
I've inserted 3 rows :
2021-12-01T00:00:00Z
2021-12-31T00:00:00Z
2021-12-31T23:59:59Z
SELECT * FROM TEST
where date > CAST("2021-12-01" as timestamp) and date < CAST("2021-12-31" as timestamp)
no rows selected
SELECT * FROM TEST
where date >= CAST("2021-12-01" as timestamp) and date <= CAST("2021-12-31" as timestamp)
2 rows : 2021-12-01T00:00:00Z and 2021-12-31T00:00:00Z
SELECT * FROM TEST
where date >= CAST("2021-12-01T00:00:00" as timestamp)and date <= CAST("2021-12-31T23:59:59" as timestamp)
3 rows : 2021-12-01T00:00:00Z , 2021-12-31T00:00:00Z and 2021-12-31T23:59:59Z
SELECT * FROM TEST
where date >= CAST("2021-12-01" as timestamp) and date < CAST("2022-01-01" as timestamp)
3 rows : 2021-12-01T00:00:00Z , 2021-12-31T00:00:00Z and 2021-12-31T23:59:59Z