question

orcohen avatar image
orcohen asked

Avoid cross join when using distance function

Hi , I am running this query : select case when p2.age < 15 then '0-15' when p2.age between 15 and 25 then '15-25' when p2.age between 26 and 39 then '26-39' when p2.age between 40 and 64 then '40-64' when p2.age > 64 then 'over 64' end as Age_Range, p2.gender, count(*) from places1 p1 join people2 p2 on 1=1 where distance(p1.lan,p1.lat,p2.lan,p2.lat) < 100 and country in ('Thailand','Vietnam','china','Malaysia') group by 1,2; The distance < 100 condition is actually a cross join and its taking me too long . Any idea how can i do it more efficient ? Thanks ! Or.
sql-server-2008sql-server-2005sqlqueryoracle
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.