I
I
Ignat2020-05-08 20:20:28
MySQL
Ignat, 2020-05-08 20:20:28

How to compare data of one column?

5eb5945026b7e775950781.png

there is such a vector, I need to find its coordinates. They are found like this A1A2 = (X2-X1; Y2-Y1).

Initial data according to the picture: table with fields: X, Y. How to do this in one SQL query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-05-08
@Bloody_Tuna

Okay, literally :

CREATE TABLE Point ( P CHAR(2), X INT, Y INT);
INSERT Point VALUES ( 'A1', 3, 4 ), ( 'A2', 8, 7 );

SELECT CONCAT( PA1.P, PA2.P ), PA2.X - PA1.X, PA2.Y - PA1.Y
  FROM Point AS PA1, Point AS PA2
  WHERE PA1.P = 'A1' AND PA2.P = 'A2'

You can check here .
Specification
Фактически у каждой СУБД есть оконные функции, реализованы по разному, вне стандарта SQL. Поэтому
Как это организовать в одном SQL запросе?
Никак без указания СУБД.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question