select 

concat(pa.bldg_id,'.',b_rcvr_call_sign,'.',a_rcvr_call_sign) as b_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.b_rcvr_call_sign,
pa.b_rcvr_desc,
pa.b_rcvr_long,
pa.b_rcvr_lat,
pa.b_rcvr_meanelev as b_rcvr_grd_elev_me,
pa.b_rcvr_raat as b_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.b_rcvr_long::numeric, pa.b_rcvr_lat::numeric),4326),2163))/1000 as numeric),4) as b_rcvr_dist_km
	
from WQTF973_WQTH343_DAT_b_1 pa, WQTF973_WQTH343_VEN_1 pb
	
where ST_Intersects(pa.b_line_4326::geometry,pb.geom::geometry)
	or st_intersects(pa.bldg_point_4326::geometry,pb.geom::geometry)


order by b_rcvr_path_id asc,
	b_rcvr_dist_km desc