File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
sql-queries-12/ideal-data-type-latitude-longitude-mysql Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1
1
-- Create example table
2
- CREATE TABLE locations (
2
+ CREATE TABLE Locations (
3
3
id INT AUTO_INCREMENT PRIMARY KEY ,
4
4
name VARCHAR (255 ),
5
5
coordinates POINT NOT NULL SRID 4326 ,
6
6
SPATIAL INDEX(coordinates)
7
7
);
8
8
-- Add example data
9
- INSERT INTO locations (name, coordinates)
9
+ INSERT INTO Locations (name, coordinates)
10
10
VALUES (' Eiffel Tower' , ST_PointFromText(' POINT(2.2945 48.8584)' , 4326 ));
11
+ INSERT INTO Locations (name, coordinates)
12
+ VALUES (' Arc de Triomphe' , ST_PointFromText(' POINT(2.2950 48.8738)' , 4326 ));
11
13
-- Query example data
12
- SELECT name,
13
- ST_Distance_Sphere(coordinates,
14
- ST_PointFromText(' POINT(49.2827 -123.1207)' , 4326 ))
15
- AS distance_meters
16
- FROM locations;
14
+ SELECT
15
+ ST_Distance_Sphere(t1 .coordinates , t2 .coordinates ) AS Distance_in_Meters
16
+ FROM
17
+ Locations AS t1,
18
+ Locations AS t2
19
+ WHERE
20
+ t1 .name = ' Eiffel Tower' AND t2 .name = ' Arc de Triomphe' ;
You can’t perform that action at this time.
0 commit comments