我正在使用ClusterPoint从我的php_api应用程序执行php_api聚合查询。下面是我使用的代码示例:
$query = "<query><Make>subaru</Make></query>
<docs>20</docs>
<offset>0</offset>
<aggregate>SUM(Count), Type, Fuel GROUP BY Type, Fuel </aggregate>";
$request = new CPS_Request('search');
$request -> setExtraXmlParam($query);
$response = $cpsConn->sendRequest($request);
$aggregates = $response -> getAggregate(DOC_TYPE_ARRAY);
$type_fuel = array_pop($aggregates);
var_dump($type_fuel[0]);ClusterPoint API按请求以数组形式返回数据,并通过规范公式SUM(Count)来计算“键”
array (size=3)
'SUM_Count' => string '2' (length=1)
'Type' => string 'Lorry' (length=5)
'Fuel' => string 'Petrol & gas' (length=12)当我更改查询时,"SUM_Count“通常会变成其他的东西,因此我正在寻找一种方法来”别名“公式结果,并为"2”的值设置一个更一致的键。
发布于 2015-03-12 12:43:32
您可以像在SQL中一样使用"as“构造来创建别名:
<aggregate>SUM(Count) as sum_c, Type, Fuel GROUP BY Type, Fuel </aggregate>https://stackoverflow.com/questions/29009815
复制相似问题