基于ORDER BY Postgresql“即时”添加排名

时间:2016-02-29 21:50:59

标签: php postgresql

我使用类似下面的内容从mySQL查询中获取结果,并根据结果中的行落在响应中的位置添加“rank”。

$service_url = 'https://something.html?';
   $curl = curl_init($service_url);
   $curl_post_data = array(
        "q" => "SELECT @rownum := @rownum + 1 Rank, q.* FROM (SELECT @rownum:=0) r,(SELECT something, another, thing from my_database order by something) q",
        "api_key" => 'XXX',
        );
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
   $curl_response = curl_exec($curl);
 echo $curl_response;

当我拿出所有添加排名的尝试时,运行正常。但现在我收到了错误回复:{"error":["syntax error at or near \":=\""]}

关于我在这里做错了什么的想法?

0 个答案:

没有答案
相关问题