D
D
Denis Nicholas2018-06-20 19:42:53
PHP
Denis Nicholas, 2018-06-20 19:42:53

How to fetch MySQL?

I have a set of entities in the database. Each entity has coordinates (ordinary numbers, both negative and positive range) x and y, in two fields. It is necessary to select only those that are included in a circle with a center (x, y) and radius R. How to do this through many queries is obvious, but how to do it with one (two or three) queries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-06-20
@dennikolas

And why do you need a bunch of requests? Only one is needed, but with parameters and a mat. functions.
Pure mathematics, nothing more.

SELECT *
FROM points p
WHERE sqrt(pow(p.x - :x, 2) + pow(p.y - :y, 2)) <= :r -- используем формулу определения расстояния между двумя точками, параметры запроса, которые нужно задать :x, :y, :r.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question