sql - PostgreSQL: Create Boolean field based on multiple rows from join -
i gathering many fields 1 database on many tables (6). 1 column causing duplication of data. want create boolean field if 1 or more of parameters true , group rest of fields.
there 1 many relationship between geometry table , address table (2 sides every road). so, problem there 1 value each side of road, therefore multiple returns. i've played around bool_or, case, coalesce, exists, array_agg can't figure out. ideas?
select g.country, g.id, n.name, gsc.geometry, gst.class, gst.length, gst.road_type, gst.one_way, gst.bridge, ga.add_type geo g left outer join name n on (g.id = n.id) left outer join geometry_address ga on (g.id = ga.id) join geometry_s gst on (g.is = gst.is) join geometry_s gs on (g.id = gs.id) join geometry_sc gsc on (gs.gsi = gsc.gsi) (g.type = 'road') , (g.country = 'usa')
thanks help.
first need provide doing , fields problem. basically, following use.
select t1.fld1, t1.fld2, bool_or(t2.fld1) mytable t1 left join my_other_table t2 on (t1.pkey1 = t2.fkey_mytable) group t1.fld1, t1.fld2;
a few recommendations in building large queries in unfamiliar territory because may problem is:
start minimal join in problem area. play until works. add rest.
keep careful track of errors , have tried.
Comments
Post a Comment