如何在Dynamo db中编写这个复杂的mysql查询

时间:2016-10-03 07:21:24

标签: php amazon-dynamodb

如何将此查询修改为dynamo db查询,我无法在聚合函数中找到示例,也无法在dynamo db中找到日期操作。

SELECT DATE(`date`) AS day ,SUM(`power`) AS power 
  FROM `ogm` 
  WHERE `id`!=0 
   AND DATE(`date`)>=DATE(NOW()) - INTERVAL 31 DAY GROUP BY day; 

1 个答案:

答案 0 :(得分:0)

使用DynamoDB客户端和scan操作来运行复杂查询。

像这样未经过测试

$client->scan([
    'TableName' => 'omg',
    'ScanFilter' => [
        'id' => [
            'AttributeValueList' => [
                'S' => '0',
            ],
            'ComparisonOperator' => 'NE',
        ],
        'date' => [
            'AttributeValueList' => [
                'S' => date('Y-m-d', strtotime('-31 days')),
            ],
            'ComparisonOperator' => 'GE',
        ],
    ],
    'ConditionalOperator' => 'AND'
]);

ComparisonOperator值列表。

请记住,此查询最多只返回1mb的数据,您必须重新循环它。并且甚至不考虑分页:D