select

concat(pa.bldg_id,'.', a_rcvr_call_sign,'.', b_rcvr_call_sign) as a_rcvr_path_id,
pa.bldg_id as bldg_number,
pa.bldg_long,
pa.bldg_lat,
pa.bldg_maxheight*3.28 as bldg_maxheight_ft,
pa.bldg_meanelevation*3.28 as bldg_meanelev_ft,
pa.bldg_address as bldg_desc,
pb.lbcs_act_1 as bldg_type,
pa.a_rcvr_call_sign,
pa.a_rcvr_desc,
pa.a_rcvr_long,
pa.a_rcvr_lat,
pa.a_rcvr_meanelev as a_rcvr_grd_elev_me,
pa.a_rcvr_raat as a_rcvr_ant_raat_me,

round(cast(st_distance(st_transform(st_setsrid(st_makepoint(pb.longitude::numeric, pb.latitude::numeric),4326),2163),
			st_transform(st_setsrid(st_makepoint(pa.a_rcvr_long::numeric, pa.a_rcvr_lat::numeric),4326),2163))/1000 as numeric),6) as a_rcvr_dist_km
	
from WQTF973_WQTH343_DAT_a_1 pa, WQTF973_WQTH343_VEN_1 pb
where st_intersects(pa.a_line_4326::geometry,pb.geom::geometry)
	or st_intersects(pa.bldg_point_4326::geometry,pb.geom::geometry)


order by a_rcvr_path_id asc,
	a_rcvr_dist_km desc