如何通过查询将组写入融合表?

时间:2015-06-26 06:29:02

标签: mysql google-fusion-tables

我想得到一个事件中的所有坐标(有eventId)根据user_id对它们进行分组然后按照时间降序排列每个坐标集并取顶部。(最后更新的坐标)..我试过这个查询。

var query3 = "https://www.googleapis.com/fusiontables/v2/query?sql=SELECT user_id,Location,Time FROM "+tableID+" WHERE event_id = 23"+" GROUP BY user_id ORDER BY Time DESC LIMIT 1"+"&key="+apiKey;

它给了我这个错误:

{
 "error": {
  "errors": [
   {
    "domain": "fusiontables",
    "reason": "badQueryCouldNotParse",
    "message": "Invalid query: (col2, LOCATION) must appear in group-by when aggregates  are present: []",
    "locationType": "parameter",
    "location": "q"
   }
  ],
  "code": 400,
  "message": "Invalid query: (col2, LOCATION) must appear in group-by when aggregates  are present: []"
 }
}

1 个答案:

答案 0 :(得分:0)

user_id可以有多个位置 - 时间组合...

您有两种可能性:

  1. GROUP BY user_id, Location, Time
  2. 使用这样的聚合:
     SELECT user_id, min(Location), min(Time) FROM ... GROUP BY user_id