2017-03-22 1 views
0

Ich habe eine Parzelle Tabelle in PostgreSQL db, die ich bestimmte Pakete abfragen muss. 3 Felder - mun, block, losSQL Parzelle Abfrage

mun1: block 46 and lot 2 

mun2: block 1 and lot 1.1 
     block 2 and lot 6 
     block 2 and lot 7 
     block 5 and lot 2 
     block 11 and lot 1 

mun3: block 11 and lot 2 
     block 11 and lot 2.2 
     block 7 and lot 2 
     block 8 and lot 2 

ich jeden zu einem Zeitpunkt abfragen kann, aber ich kann nicht herausfinden, wie sie in einer Abfrage zu tun ... irgendwelche Vorschläge mit Syntax und Logik

ex:

select * from parcels where mun = 'mun1' and block = '46' and lot = '2' 
+0

Können Sie einige Beispieldaten bereitstellen? Deine Frage ist nicht klar, denke ich. –

+0

@GiorgosAltanis check edit – ziggy

Antwort

0

So ähnlich?

select * from parcels 
where (mun = 'mun1' and block = '46' and lot = '2') 
or (mun = 'mun2' and 
    (block = '1' and lot = '1.1' 
    or block = '2' and lot = '6' 
    or block = '2' and lot = '7' 
    or block = '5' and lot = '2' 
    or block = '11' and lot = '1' 
    ) 
) 
or (mun = 'mun3' and 
    (block = '11' and lot = '2' 
    or block = '11' and lot = '2.2' 
    or block = '7' and lot = '2' 
    or block = '8' and lot = '2' 
    ) 
) 
+0

okay ja, das ist eine Art der Logik, die ich wollte Ich werde dies versuchen – ziggy

+0

wahrscheinlich einfacher, eine temporäre Tabelle/Tabelle Variable mit den gewünschten Werten zu erstellen und eine innere Verbindung –

+0

@MarshallTigerus würde möchtest du deine Antwort teilen? – ziggy