WITH facility_distance AS (
select 2 * 6374.612 * asin(sqrt((sin(radians((m.latitude - 24.7135517) / 2))) ^ 2 + cos(radians(24.7135517)) * cos(radians(m.latitude)) * (sin(radians((m.longitude - 46.67529569999999) / 2))) ^ 2)) as dist
,m.id as id from facility_schema.cas_facility as m
),facility_id AS(select fd.id as id,dist from facility_distance as fd where fd.dist<=100)
SELECT cf.id, cf.address_line1, cf.address_line1_ar, cf.contact_no_1, cf.contact_no_2,
cf.email, cf.end_working_hour, cf.facility_description, cf.facility_description_ar,
cf.facility_name, cf.facility_name_ar, cf.fax_1, cf.fax_2, cf.facility_cd, cf.latitude,
cf.longitude, cf.start_working_hour, cf.website, cf.working_days, cf.cas_directorate_id, cf.cas_facility_type_id,cf.created_by,cf.created_date,cf.modified_by,cf.modified_date,cf.his,cf.his_endpoint,cf.moh_facility_id,cf.country_code,cf.mobile_country_code,cf.specialized_center_flag
FROM facility_schema.cas_facility cf inner join facility_id on (cf.id =facility_id.id) join facility_schema.cas_facility_type ft on ft.id = cf.cas_facility_type_id where ft.enable_direct_appointment=true order by facility_id.dist asc
with select
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.