0

我想使用 BETWEEN 操作在 nosql 数据库中进行查询?我想做这样的事情:

SELECT * FROM table 
WHERE column_timestamp BETWEEN '2021-01-01'
AND '2021-12-31'

如何在 NoSQL 数据库中执行此查询?支持 BETWEEN 吗?

4

1 回答 1

0

在您的情况下,因为您的列似乎是时间戳,您需要将时间戳值转换为 TIMESTAMP 类型。然后你只需使用 <= 和 >= 运算符。

当只使用日期而不提供时间进行查询时要小心。这是一个使用 <、<=、>=、> 的测试用例。


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

于 2021-05-31T12:35:56.020 回答