2017-02-06 5 views
1

Ich habe SQL-Abfrage, die in Tabelle mit Adressfeldern sucht. Mein Problem ist im Stadtbereich. Ich nahm Suchspalte Straßen mit Hausnummer und ohne ihn aber ich habe die Teilung von Nachbarschaften vergessen wie: Kolin IV, Kolín II, etc. Meine Frage ist, kann irgendwie aus der Spalte mit der SQL-Funktion nur den Namen der Stadt zu vergleichen ohne Angabe, welchem ​​Bezirk der Bezirk angehört?SQL - LIKE Suche in Adressfeldern

$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", ""); 
+0

BTW: wenn ich im Vergleich: Vrchlické 789, Kolín IV 28002 - sein OK Vrchlické 789, Kolín 28002 - sein FAIL –

+0

Vergleicht man alles, um die vollständige Adresse scheint nicht notwendig. –

Antwort

0

Sie können feststellen, dass dies funktioniert:

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

Dies ist jedoch andere Probleme einführen könnte, wenn die Städte aus mehreren Wörtern Namen haben.

+0

Vielen Dank –