MySQL Forums
Forum List  »  Newbie

SQRT / Pythagoras Query problem
Posted by: gary campbell
Date: May 14, 2014 11:09AM

Hi, can someone please put me out of my misery. I have been trying to teach myself databasing (don't ask why), and have so far succeeded at a very basic level. However, I am now, and have been for weeks, stuck on this (probably) quite simple problem:

I'm using MySQL Workbench and server v.6.1

I have created several tables which feed data into the table to which this query relates - lets call it LOC. This table's columns are:

a_ID | a_name | a_address | a_X_coord | a_Y_coord | b_ID | b_Name | b_X_coord | b_Y_coord
-----------------------------------------------------------------------------

NOTE: All the coords are simple single digit X&Y's (eg X=2, Y=8), NOT geolocation coords. I'll move onto more accurate / complex geolocational problems using radians / COS etc after I've got the basics.

The problem: I'm trying to create a query that, when a user selects any 'b_Name', the query returns all the 'a' data (but not the coords) with their distances from the selected 'b' location in a table that will look like:

b_Name | a_Name | a_address | Distance_of_a_from b |
----------------------------------------------

The formula I'm using to calculate a's distance from b is pythagoras: SQRT(((a_X - b_X) * (a_X - b_X)) + ((a_Y - b_Y) * (a_Y - b_Y))) which I think is correct.


1. I've lost count of my efforts to create this query and all have returned syntax errors and no amount of tweaking rectifies it, (which leads me to believe I'm way off the mark), hence why I'm turning to the experts for help. I can post my latest failed effort if this will help.

Any help will be greatly appreciated.

Options: ReplyQuote


Subject
Written By
Posted
SQRT / Pythagoras Query problem
May 14, 2014 11:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.