You can use the Haversine formula for calculating the distance between the locations. However, if you do much with latitude, longitude you would be better off installing PostGis (create extension postgis). It has all the necessary functionality for handling geographic data. In this case:
with r (id, resort, r_loc) as
( select id, resort, ST_SetSRID(ST_MakePoint(longitude, latitude),4326)::geography
from resorts
)
, s (id, dt, s_loc) as
( select id, snowed_on, ST_SetSRID(ST_MakePoint(longitude, latitude),4326)::geography
from snows
)
select *, ST_Distance(r_loc, s_loc) distance
from r cross join s
order by ST_Distance(r_loc, s_loc);
Alternately, you can go a step further and instead of storing longitude and latitude columns and doing the necessary conversion on each query do the conversion once on insertion and store the column as geography
data type. So (apply the same for snows
table):
create table resorts_g ( id integer generated always as identity
primary key
, resort text
, loc geography
);
The query then reduces to just the main query above without the CTEs. If you occasionally need longitude/latitude as separate columns you can extract them individually or together:
select id, resort
, ST_X(loc::geometry) longitude
, ST_Y(loc::geometry) latitude
FROM resorts_g;
See demo here with both versions and then some.