javascript - Google Fusion Table 的复杂 SQL 查询出现问题。我可以在查询中使用外部值吗?

标签 javascript sql google-maps-api-3 google-fusion-tables

这个项目的基本轮廓是它是伦敦区之间旅程时间的视觉表示。

到目前为止,我已经设置了一个可以很好地响应基本查询的 google 融合表。但现在我正在尝试根据往返所选多边形的行程时间来更改融合表多边形的颜色。

function fillcolour(match) {
  var limit = 0;
  var filter = [];

  for (x in match) {
    if (limit < 5) {
      var duration = match[x];
      if (dataraw[1]) {
          //-------75 and 65 are stand in values at the moment. They will later be filled by variables.
          filter.push("(" + generateWhere(x, duration, 75, 65) + ")");
      }
      limit++;
    }
  }
  where = filter.join(' OR ');

  PolygonLayer.setOptions({
    query: {
      select: 'shape',
      from: mapTable
    },
    styles: [{
      polygonOptions: {
        fillColor: "#000FFF",
        fillOpacity: .8
      }
    },
    {
      where: where,
      polygonOptions: {
        fillColor: "#FFF000"
      }
    }],
  })
};

function generateWhere(Keys, duration, high, low) {
  var whereClause = [];
  whereClause.push("name");
  whereClause.push(" = '");
  whereClause.push(Keys);
  whereClause.push("' AND ");
  whereClause.push(duration);
  whereClause.push(" >= ");
  whereClause.push(low);
  whereClause.push(" AND ");
  whereClause.push(duration);
  whereClause.push(" < ");
  whereClause.push(high);
  return whereClause.join('');
}

我知道可能有一种更简单的方法来处理多边形选项,但目前我的 SQL 查询并没有按照我希望的方式运行。

这是被输入 where 语句的查询:

(name = 'Abbey Wood' AND 80 >= 65 AND 80 < 75) OR (name = 'Acton' AND 74 >= 65 AND 74 < 75) OR (name = 'Anerley' AND 46 >= 65 AND 46 < 75)

有人知道为什么这行不通吗?

最佳答案

(name = 'Abbey Wood' AND 80 >= 65 AND 80 < 75) OR (name = 'Acton' AND 74 >= 65 AND 74 < 75) OR (name = 'Anerley' AND 46 >= 65 AND 46 < 75)

查询有两个问题

1) Fusion Table Queries :

"You must use quotes around any column names in the select or where fields that contain spaces, reserved words, or that do not begin with a letter".

2) Row and Query SQL Reference :

"OR is not supported."

因此您需要添加引号并将 OR 子查询拆分为单独的查询

styles: [{
    polygonOptions: {
        fillColor: "#000FFF",
        fillOpacity: .8
    }
},
{
    where: "name = 'Abbey Wood' AND '80' >= 65 AND '80' < 75",
    polygonOptions: {
        fillColor: "#FFF000"   
    }
},
{
    where: "name = 'Acton' AND '74' >= 65 AND '74' < 75",
    polygonOptions: {
        fillColor: "#FFF000"    
    }
},
{
    where: "name = 'Anerley' AND '46' >= 65 AND '46' < 75",
    polygonOptions: {
        fillColor: "#FFF000"    
    }
}]

关于javascript - Google Fusion Table 的复杂 SQL 查询出现问题。我可以在查询中使用外部值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50124363/

相关文章:

javascript - 如何从angularjs中的文本框中过滤数据

javascript - Node - 如何在 path.join 中使用变量?

php - 表格中的常用字数统计,而不仅仅是一行

flutter - 插件项目 :location_web not found. 请更新 settings.gradle。我该如何解决?

javascript - 谷歌地图加载时间较长

javascript - md菜单 : Cannot read property 'open' of null

javascript - Angularjs 正式嵌套形式

sql - 按名称删除一组存储过程

sql - 使用 native 客户端驱动程序从 Delphi 代码创建触发器

java.net.ConnectException : Connection refused with Google Maps