Dynamodb 最大值

2023-07-05Python开发问题
3

本文介绍了Dynamodb 最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 Dynamodb.我有一个简单的 Employee 表,其中包含 id、name、salary、doj 等字段.dynamodb 中 select max(salary) from employee 的等效查询是什么?

I'm using Dynamodb. I have a simple Employee table with fields like id, name, salary, doj, etc. What is the equivalent query of select max(salary) from employee in dynamodb?

推荐答案

你可以为你的模式建模:

You can model your schema something like:

  • employee_id,作为分区键
  • salary,作为表或本地二级索引的排序键.
  • employee_id, as partition-key
  • salary, as sort-key of the table or local secondary index.

然后,Query 表中给定的 employee_idScanIndexForward 为 false,然后选择第一个返回的条目.由于 employee_id 的所有行都以排序方式存储,因此按 desc 顺序排列的第一个条目将是具有最高 salary 的条目.

Then, Query your table for given employee_id, with ScanIndexForward as false, and pick the first returned entry. Since all rows one employee_id are stored in sorted fashion, the first entry in desc order will be the one with highest salary.

您也可以将 Limit 保持为 1,在这种情况下 DynamoDB 将只返回一条记录.

You can also keep Limit as 1, in which case DynamoDB will return only one record.

相关文档此处.

这篇关于Dynamodb 最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11