SOQL 查询中的 LIKE 或 CONTAINS
LIKE or CONTAINS in SOQL Query
我正在尝试使用 JavaScript 代码从以下 URL 获取一些数据:
http://data.cityofnewyork.us/resource/erm2-nwe9.json
这就是我构建查询的方式:
//data URL variables
var start_date = '2013-08-01'; //YYYY-MM-DD
var end_date = '2013-08-08'; //YYYY-MM-DD
var c_type = 'Noise'; // Complaint Type
// Build the data URL
var URL = "http://data.cityofnewyork.us/resource/erm2-nwe9.json"; // API Access Endpoint
URL += "?";
URL += "$where=";
URL += "(latitude IS NOT NULL)";
URL += " AND ";
URL += "(complaint_type='" + c_type + "')";
URL += " AND ";
URL += "(created_date>='" + start_date + "') AND (created_date<='" + end_date + "')";
URL += "&$group=complaint_type,descriptor,latitude,longitude";
URL += "&$select=descriptor,latitude,longitude,complaint_type";
URL = encodeURI(URL);
到目前为止我是如何测试它的:
$.getJSON(URL, function(data)
{
console.log(data)
});
现在它工作正常,但我应该考虑任何包含单一世界的投诉类型 ("Noise"):
URL += "(complaint_type LIKE '%" + c_type + "%')";
编码URL(似乎没问题):
http://data.cityofnewyork.us/resource/erm2-nwe9.json?$where=(latitude%20IS%20NOT%20NULL)%20AND%20(complaint_type%20LIKE%20'%25Noise%25')%20AND%20(created_date%3E='2013-08-01')%20AND%20(created_date%3C='2013-08-08')&$group=complaint_type,描述符,纬度,经度&$select=描述符,纬度,经度,complaint_type
错误:
{
"code" : "query.compiler.malformed",
"error" : true,
"message" : "Error, could not parse SoQL query \"select descriptor,latitude,longitude,complaint_type from #erm2-nwe9 where (latitude IS NOT NULL) AND (complaint_type LIKE '%Noise%') AND (created_date>='2013-08-01') AND (created_date<='2013-08-08') group by complaint_type,descriptor,latitude,longitude\"",
"data" : {
"query" : "select descriptor,latitude,longitude,complaint_type from #erm2-nwe9 where (latitude IS NOT NULL) AND (complaint_type LIKE '%Noise%') AND (created_date>='2013-08-01') AND (created_date<='2013-08-08') group by complaint_type,descriptor,latitude,longitude"
}
}
documentation 好像可以用 LIKE,但是我用不了。
我不知道该怎么做。
我刚刚弄清楚它是如何工作的,它似乎不接受条件中的百分号 '%',它应该以反斜杠开头(或者只是斜杠,无论如何)。
所以这是使用 'like' 语句的有效 URL:
http://data.cityofnewyork.us/resource/erm2-nwe9.json?$where=(latitude%20IS%20NOT%20NULL)%20AND%20(complaint_type%20like%20%27\%Noise\%%27)%20AND%20(created_date%3E=%272013-08-01%27)%20AND%20(created_date%3C=%272013-08-08%27)&$group=complaint_type,descriptor,latitude,longitude&$select=descriptor,latitude,longitude,complaint_type
或代码中的适当行:
URL += "(complaint_type LIKE '\%" + c_type + "\%')";
让我知道它是否有效,很抱歉没有及时回复,我真的没有使用 Salesforce 和 SOQL 的经验。但多亏了你,我还有另一个新的 space 可以探索:)
我正在尝试使用 JavaScript 代码从以下 URL 获取一些数据:
http://data.cityofnewyork.us/resource/erm2-nwe9.json
这就是我构建查询的方式:
//data URL variables
var start_date = '2013-08-01'; //YYYY-MM-DD
var end_date = '2013-08-08'; //YYYY-MM-DD
var c_type = 'Noise'; // Complaint Type
// Build the data URL
var URL = "http://data.cityofnewyork.us/resource/erm2-nwe9.json"; // API Access Endpoint
URL += "?";
URL += "$where=";
URL += "(latitude IS NOT NULL)";
URL += " AND ";
URL += "(complaint_type='" + c_type + "')";
URL += " AND ";
URL += "(created_date>='" + start_date + "') AND (created_date<='" + end_date + "')";
URL += "&$group=complaint_type,descriptor,latitude,longitude";
URL += "&$select=descriptor,latitude,longitude,complaint_type";
URL = encodeURI(URL);
到目前为止我是如何测试它的:
$.getJSON(URL, function(data)
{
console.log(data)
});
现在它工作正常,但我应该考虑任何包含单一世界的投诉类型 ("Noise"):
URL += "(complaint_type LIKE '%" + c_type + "%')";
编码URL(似乎没问题):
http://data.cityofnewyork.us/resource/erm2-nwe9.json?$where=(latitude%20IS%20NOT%20NULL)%20AND%20(complaint_type%20LIKE%20'%25Noise%25')%20AND%20(created_date%3E='2013-08-01')%20AND%20(created_date%3C='2013-08-08')&$group=complaint_type,描述符,纬度,经度&$select=描述符,纬度,经度,complaint_type
错误:
{
"code" : "query.compiler.malformed",
"error" : true,
"message" : "Error, could not parse SoQL query \"select descriptor,latitude,longitude,complaint_type from #erm2-nwe9 where (latitude IS NOT NULL) AND (complaint_type LIKE '%Noise%') AND (created_date>='2013-08-01') AND (created_date<='2013-08-08') group by complaint_type,descriptor,latitude,longitude\"",
"data" : {
"query" : "select descriptor,latitude,longitude,complaint_type from #erm2-nwe9 where (latitude IS NOT NULL) AND (complaint_type LIKE '%Noise%') AND (created_date>='2013-08-01') AND (created_date<='2013-08-08') group by complaint_type,descriptor,latitude,longitude"
}
}
documentation 好像可以用 LIKE,但是我用不了。
我不知道该怎么做。
我刚刚弄清楚它是如何工作的,它似乎不接受条件中的百分号 '%',它应该以反斜杠开头(或者只是斜杠,无论如何)。
所以这是使用 'like' 语句的有效 URL:
http://data.cityofnewyork.us/resource/erm2-nwe9.json?$where=(latitude%20IS%20NOT%20NULL)%20AND%20(complaint_type%20like%20%27\%Noise\%%27)%20AND%20(created_date%3E=%272013-08-01%27)%20AND%20(created_date%3C=%272013-08-08%27)&$group=complaint_type,descriptor,latitude,longitude&$select=descriptor,latitude,longitude,complaint_type
或代码中的适当行:
URL += "(complaint_type LIKE '\%" + c_type + "\%')";
让我知道它是否有效,很抱歉没有及时回复,我真的没有使用 Salesforce 和 SOQL 的经验。但多亏了你,我还有另一个新的 space 可以探索:)