【问题标题】:SQL - LIKE search in address fieldsSQL - 在地址字段中进行 LIKE 搜索
【发布时间】:2017-06-23 11:03:23
【问题描述】:

我有 SQL 查询,它在带有地址字段的表中搜索。我的问题是在城市领域。 我假设搜索列街道有门牌号但没有他,但我忘记了社区的划分,例如:Kolin IV、Kolín II 等。我的问题是,可以以某种方式从使用 SQL 函数的列中仅比较城市名称而没有该地区所属的任何迹象?

$where = " WHERE (LOWER(city) LIKE LOWER('%$fullAddress%')
 OR LOWER(street) LIKE LOWER('%$fullAddress%')
 OR CAST(postal_code AS TEXT) LIKE LOWER('%$fullAddress%')
 OR CAST(house_number AS TEXT) LIKE LOWER('%$fullAddress%')
 OR (LOWER(street || ', ' || city) LIKE LOWER('%$fullAddress%'))
 OR (LOWER(street || ' ' || CAST(house_number AS TEXT)) LIKE LOWER('%$fullAddress%'))
 OR (LOWER(city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER('%$fullAddress%'))
 OR (LOWER(street || ', ' || city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER('%$fullAddress%'))
 OR (LOWER(street || ' ' || CAST(house_number AS TEXT) || ', ' || city) LIKE LOWER('%$fullAddress%'))
 OR (LOWER(street || ' ' || CAST(house_number AS TEXT) || ', ' || city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER('%$fullAddress%'))) AND deleteby is null";
$results = $fce->_slctSQL("public.configurations_view", "", "services", $where, "", " ORDER BY city ASC, street ASC, house_number ASC, postal_code ASC", "");

【问题讨论】:

  • 顺便说一句:当我比较时:Vrchlické 789,Kolín IV 28002 - 它的 OK Vrchlické 789,Kolín 28002 - 它的失败
  • 似乎没有必要将所有内容与完整地址进行比较。

标签: sql postgresql search full-text-search


【解决方案1】:

你可能会发现这行得通:

 OR (LOWER(city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER(REPLACE('%$fullAddress%', ' ', '%'))

但是,如果城市有多个单词的名称,这可能会带来其他问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 2014-02-10
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    相关资源
    最近更新 更多