[opengeodb] nur deutschland

Stephan Schuster stephan.s at gmx.net
Don Mar 20 17:42:07 CET 2008


> Ich bekomms immer noch nicht hin.
>
> Ich hab:
>
> SELECT text.text_val as plz, coord.lat as lat, coord.lon as lon
> FROM geodb_textdata as text
> LEFT JOIN geodb_coordinates as coord
> ON(text.loc_id = coord.loc_id)
> WHERE text.loc_id IN (SELECT loc_id FROM geodb_textval WHERE
> geodb_textval.text_type = 50030000)
> AND text.text_type = 50030000
> ORDER BY plz
>
> die liefert mir aber zu jeder Postleitzahl mindestens 3 Datensätze. Wie
> bekomm ich denn nun daraus einen eindeutigen? Ich weiss das lat und lon
> unterschiedliche Werte haben, aber der erste (mit den kürzeren lat, lon
> Einträgen) würde mir für jede PLZ reichen. DISTINCT ist irgendwie nicht
> so ganz das was ich brauch.

Die Tabelle geodb_textval existiert bei mir nicht. Folgende Abfrage
liefert wohl, was du suchst:

SELECT plz.text_val AS plz, coord.lat, coord.lon
FROM geodb_textdata plz
LEFT JOIN geodb_coordinates coord ON plz.loc_id = coord.loc_id
WHERE plz.text_type     = 500300000
ORDER BY plz

Willst Du noch die entsprechenden Orts-Namen dazu, verwendest Du folgendes:

SELECT plz.text_val, name.text_val, coord.lat, coord.lon
FROM geodb_textdata plz
LEFT JOIN geodb_textdata name ON name.loc_id=plz.loc_id
LEFT JOIN geodb_coordinates coord ON plz.loc_id = coord.loc_id
WHERE plz.text_type     = 500300000  /* ID für Postleitzahl */
  AND name.text_type    = 500100000 /* ID für name */;

wobei dies natürlich Redundanzen beim Städte-Namen erzeugt...

Gruß
Stephan