select members.relation_id,line.osm_id as line_id,tags.k as relation_key,tags.v as relation_value,line.kct_red,line.kct_green,line.kct_blue,line.kct_yellow
from gis.cz_line line
left join osm.current_relation_members members on line.osm_id=members.member_id and members.member_type='Way'
left join osm.current_relation_tags tags on tags.relation_id=members.relation_id
where line.osm_id > 0 and (
     line.kct_red is not NULL and tags.k='kct_red'
  or line.kct_green is not NULL and tags.k='kct_green'
  or line.kct_blue is not NULL and tags.k='kct_blue'
  or line.kct_yellow is not NULL and tags.k='kct_yellow'
  );
