douyoupingji7238 2015-05-26 17:05
浏览 12

DynamoDB计数组

We are trying to search a dynamodb, and need to get count of objects within a grouping, how can this be done?

I have tried this, but when adding the second number, this doesn't work:

$search = array(
    'TableName'     => 'dev_adsite_rating',
    'Select'        => 'COUNT',
    'KeyConditions' => array(
        'ad_id' => array(
            'ComparisonOperator' => 'EQ',
            'AttributeValueList' => array(
                array('N' => 1039722, 'N' => 1480)
            )
        )
    )
);
$response = $client->query($search);

The sql version would look something like this:

select ad_id, count(*) 
from dev_adsite_rating
where ad_id in(1039722, 1480)
group by ad_id;

So, is there a way for us to achieve this? I can not find anything on it.

  • 写回答

1条回答 默认 最新

  • douzhi2017 2015-06-05 23:28
    关注

    Trying to perform a query like this on DynamoDB is slightly trickier than in an SQL world. To perform something like this, you'll need to consider a few things

    1. EQ ONLY Hash Key: To perform this kind of query, you'll need to make two queries (i.e. ad_id EQ 1039722 / ad_id EQ 1480)
    2. Paginate through query: Because dynamodb returns your result set in increments, you'll need to paginate through your results. Learn more here.
    3. Running "Count": You can take the "Count" property from the response and add it to the running total as you're paginating through the results of both queries. Query API
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制