查询返回 Table 中的所有数据

Query Returning All Data In Table

我想弄清楚为什么此查询会返回 table:

中的所有数据
State IN ('North Dakota') AND ('Homicide Offenses' > 0 OR 'Assault Offenses' > 0)

我在下面包含了用于生成此语句的代码。该代码适用于单个搜索,例如:

State IN ('North Dakota') AND 'Homicide Offenses' > 0

但对其他任何东西都不起作用。感谢您提供任何见解。

function getWhere() {
    var caps = getCAPS(); //Returns an array of user selections
    var states = getStates(); //Returns an array of selected states
    var where = "State IN (" + states.join(",") + ')';

    if (caps.length) {
        if (caps.length == 1) {
            where = where + " AND " + caps.pop();
        } else {
            where += " AND (";
            while(caps.length) {
                if(caps.length == 1) {
                    where += caps.pop() + ")";
                } else {
                    where += caps.pop() + " OR ";
                }
            }   
        }
    }

    return where;
}

我没有在代码中看到错误,但试试看它是否修复了它。只需像对州所做的那样使用连接将攻击加在一起,并检查总和是否 > 0。

function getWhere() {
    var caps = getCAPS(); //Returns an array of user selections
    var states = getStates(); //Returns an array of selected states
    return where = "State IN (" + states.join(",") + ") AND " + caps.join("+") + " > 0"
}

您需要将 getCAPS 更改为 return 简单的列表

"'Homicide Offenses'"

而不是

"'Homicide Offenses' > 0"

无论如何,这可能是更好的方法。

这些列或列中的值吗?您可能需要将 where 语句更改为如下所示:

State IN ('North Dakota') AND Offence IN ('Homicide Offenses' , 'Assault Offenses')

试试这个。 '声明在 ('North Dakota') 和 ('Homicide Offenses' > 0 或 'Assault Offenses' > 0) 和声明在 ('North Dakota')'

我想这应该适合你。

如果两者都
State IN ('North Dakota') AND ('Homicide Offenses' > 0)
State IN ('North Dakota') AND ('Assault Offenses' > 0)
确实按预期工作,我会检查是否

<filter_condition>
A Boolean expression (returns TRUE or FALSE). Only table rows where the condition is TRUE will be included in the results of the SELECT. Use AND to combine multiple filters into a single query. [...] OR is not supported.

(from Fusion Tables REST API - Row and Query SQL Reference) 真的要读作:没有OR。 (......以及它是否导致 - 当被忽略时 - 观察到的效果。)

(此 "OR is not supported" 出现在文档的 SELECTCREATE VIEW <filter_condition> 部分...)。