【问题标题】:Identifying similar string values in two columns识别两列中的相似字符串值
【发布时间】:2016-08-12 18:43:49
【问题描述】:

例如,我有以下两列表格,Address1refAddr

表格中的一些示例数据如下所示。

我想比较两列是否匹配。显然在这张表中,5235 JFK BLVD & 5235 John F Kennedy 是一对,424 N 2ND ST & 424 NORTH SECOND 是一对。

SQL 或 SSIS 中是否有我可以用来删除非配对结果并保留配对的方法?

【问题讨论】:

  • 地址匹配和修复是一种特殊用途的软件,通常不包含在数据库中。
  • 购买一个主数据管理软件来做到这一点。
  • 在 SSIS 中使用带有正则表达式的脚本组件,并在附加列中标记那些匹配的行,然后您可以过滤这些行。
  • regex 在这种情况下很糟糕......那里有很多字符串相似性函数,它们都适用于不同的事情,这个特定的地址问题你需要更多的逻辑,例如别名表。诀窍是您必须拥有标准化和解析的地址,然后进行比较。但一种更简单的方法(通常比@dfundako 的 MDM 建议更便宜)是对它们进行地理编码,然后比较地理点。根据您数据集的大小,您可以以相对较低的成本执行此操作。
  • 哦,我同意 Gordon 的观点,即它通常不在数据库中,但由于我们的跨国系统的特殊需要,我喜欢它,并且为此目的编写了一些 CLR

标签: sql sql-server tsql ssis


【解决方案1】:

一个选项是您可以使用 GOOGLE API 对地址进行地理编码,解析 JSON 结果以返回更标准化的结果。这可能很耗时,但您会对数据更有信心。

API 允许(我相信)每天 2,500 次点击,但您可以购买更多。

例如,我选择了 5232 JFK Blvd 并添加了邮政编码 72116 以缩小搜索范围。如果没有邮政编码,它会返回多个地址(NY、NJ、AR 等)

https://maps.googleapis.com/maps/api/geocode/json?address=5232%20JFK%20Blvd&72116sensor=false

关键要素可能是:

formatted_address: "5232 J.F.K. Blvd, North Little Rock, AR 72116, USA",
or
long_name: "John F. Kennedy Boulevard",

返回

{
results: [
{
address_components: [
{
long_name: "5232",
short_name: "5232",
types: [
"street_number"
]
},
{
long_name: "J.F.K. Boulevard",
short_name: "J.F.K. Blvd",
types: [
"route"
]
},
{
long_name: "North Little Rock",
short_name: "North Little Rock",
types: [
"locality",
"political"
]
},
{
long_name: "Hill Township",
short_name: "Hill Township",
types: [
"administrative_area_level_3",
"political"
]
},
{
long_name: "Pulaski County",
short_name: "Pulaski County",
types: [
"administrative_area_level_2",
"political"
]
},
{
long_name: "Arkansas",
short_name: "AR",
types: [
"administrative_area_level_1",
"political"
]
},
{
long_name: "United States",
short_name: "US",
types: [
"country",
"political"
]
},
{
long_name: "72116",
short_name: "72116",
types: [
"postal_code"
]
}
],
formatted_address: "5232 J.F.K. Blvd, North Little Rock, AR 72116, USA",
geometry: {
bounds: {
northeast: {
lat: 34.8032656,
lng: -92.2538364
},
southwest: {
lat: 34.8032599,
lng: -92.2538538
}
},
location: {
lat: 34.8032599,
lng: -92.2538364
},
location_type: "RANGE_INTERPOLATED",
viewport: {
northeast: {
lat: 34.8046117302915,
lng: -92.2524961197085
},
southwest: {
lat: 34.8019137697085,
lng: -92.2551940802915
}
}
},
place_id: "EjI1MjMyIEouRi5LLiBCbHZkLCBOb3J0aCBMaXR0bGUgUm9jaywgQVIgNzIxMTYsIFVTQQ",
types: [
"route",
"street_address"
]
},
{
address_components: [
{
long_name: "5232",
short_name: "5232",
types: [
"street_number"
]
},
{
long_name: "John F. Kennedy Boulevard",
short_name: "John F. Kennedy Blvd",
types: [
"route"
]
},
{
long_name: "West New York",
short_name: "West New York",
types: [
"locality",
"political"
]
},
{
long_name: "Hudson County",
short_name: "Hudson County",
types: [
"administrative_area_level_2",
"political"
]
},
{
long_name: "New Jersey",
short_name: "NJ",
types: [
"administrative_area_level_1",
"political"
]
},
{
long_name: "United States",
short_name: "US",
types: [
"country",
"political"
]
},
{
long_name: "07093",
short_name: "07093",
types: [
"postal_code"
]
}
],
formatted_address: "5232 John F. Kennedy Blvd, West New York, NJ 07093, USA",
geometry: {
bounds: {
northeast: {
lat: 40.78574,
lng: -74.0231416
},
southwest: {
lat: 40.7857366,
lng: -74.0231598
}
},
location: {
lat: 40.78574,
lng: -74.0231416
},
location_type: "RANGE_INTERPOLATED",
viewport: {
northeast: {
lat: 40.78708728029149,
lng: -74.02180171970849
},
southwest: {
lat: 40.7843893197085,
lng: -74.0244996802915
}
}
},
place_id: "Ejc1MjMyIEpvaG4gRi4gS2VubmVkeSBCbHZkLCBXZXN0IE5ldyBZb3JrLCBOSiAwNzA5MywgVVNB",
types: [
"route",
"street_address"
]
}
],
status: "OK"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    相关资源
    最近更新 更多