Jump to content
php.lv forumi

postgresql alias iekš where


Recommended Posts

select u.id,
st_distance_sphere(
                ST_GeomFromText(concat('POINT(',u.longitude,' ',u.latitude,')'), 4326),
                ST_GeomFromText(concat('POINT(22.286756 56.624693)'), 4326)
) as closeness
from users u
where u.longitude is not null and u.latitude is not null
order by closeness

Kā man iekš kverija ielikti pārbaudi uz distanci? closeness <= 50000

 

Where nevar ielikt imho "ERROR:  column "closeness" does not exist" alias nestrādā. 

Link to post
Share on other sites
  • 3 weeks later...

Atgriežoties tēmas. Tiešām nav labāka varianta?

select u.id,
st_distance_sphere(
    ST_SetSrid(ST_MakePoint(u.longitude::numeric, u.latitude::numeric), 4326),
    ST_SetSrid(ST_MakePoint(60.02402367490043, 30.437835716692238), 4326)) 
as closeness
from users u
where u.is_online = true and and u.longitude is not null and u.latitude is not null
and 10000 < (select st_distance_sphere(
    ST_SetSrid(ST_MakePoint(u.longitude::numeric, u.latitude::numeric), 4326),
	ST_SetSrid(ST_MakePoint(60.02402367490043, 30.437835716692238), 4326)))
order by closeness
limit 10
Link to post
Share on other sites

Man liekas, ka iesakot subquery, domāja ko šādu

select sub.*
from (select u.id,
        st_distance_sphere(
          ST_SetSrid(ST_MakePoint(u.longitude::numeric, u.latitude::numeric), 4326),
          ST_SetSrid(ST_MakePoint(60.02402367490043, 30.437835716692238), 4326)) 
        as closeness
        from users u
        where u.is_online = true and and u.longitude is not null and u.latitude is not null
) as sub
where 10000 < sub.closeness
order by sub.closeness
limit 10
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...