SQL parcel查询

时间:2017-03-22 20:12:55

标签: sql

我在postgreSQL db中有一个parcel表,我需要查询特定的parcel。 3个领域 - mun,block,lot

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

我可以一次查询每一个但我无法弄清楚如何在一个查询中执行它们...任何带语法和逻辑的建议

前:

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

1 个答案:

答案 0 :(得分:0)

这样的东西?

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'
    )
)