【发布时间】:2021-06-01 09:59:16
【问题描述】:
如何选择给定日期范围内的所有项目?
SELECT * FROM GameScores where createdAt >= start_date && createAt
我想进行这样的查询。是否需要创建全局二级索引?
我试过了
public void getItemsByDate(Date start, Date end) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String stringStart = df.format(start);
String stringEnd = df.format(end);
ScanSpec scanSpec = new ScanSpec();
scanSpec.withFilterExpression("CreatedAt BETWEEN :from AND :to")
.withValueMap(
new ValueMap()
.withString(":from", stringStart)
.withString(":to", stringEnd));
ItemCollection<ScanOutcome> items = null;
items = gamesScoresTable.scan(scanSpec);
}
但这不起作用,我得到的结果比预期的要少。
【问题讨论】:
-
你的密钥结构是什么样的,你的数据是什么样的?基于这些信息,我们只能说:视情况而定。
-
我不知道 java sdk 是如何工作的,但是您正在扫描,所以结果很可能会被分页,这可以解释为什么您得到的结果比预期的要少。跨度>
标签: java amazon-web-services amazon-dynamodb