简体   繁体   中英

Compound SELECT query postgreSQL / postGIS

Probaby a simple syntax issue but I have this postGIS query I'd like to run on a single table:

SELECT 
    ST_Overlaps(g1.geom,g2.geom) AS asr_01
FROM 
    ch03.my_polygons g1, ch03.my_polygons g2
WHERE 
    g1.agent_type = 0 AND g2.agent_type != 0 AND g1.sim_time = 0.0

which works as expected, but I'd like to also select an adjacent column such as this

SELECT 
    agent_id 
FROM 
    ch03.my_polygons
WHERE 
    agent_type != 0

which also works fine but how do I combine these? Tried this...

SELECT 
    agent_id,
    ST_Overlaps(g1.geom,g2.geom) AS asr_01
FROM 
    ch03.my_polygons,
    ch03.my_polygons g1, ch03.my_polygons g2 
WHERE
    agent_type != 0,
    g1.agent_type = 0 AND g2.agent_type != 0 AND g1.sim_time = 0.0

Possible? Another way to get around this? Thanks

OK I figured it out with combining the use of the variables...

SELECT 
    g2.agent_id,
    ST_Overlaps(g1.geom,g2.geom) AS asr_01
FROM 
    ch03.my_polygons g1, ch03.my_polygons g2 
WHERE
    g1.agent_type = 0 AND g2.agent_type != 0 AND g1.sim_time = 0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM