473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Order by closeness to integer

Hi

My queries need to search for 1600 higher, and 1600 lower than a given
integer. One integer is a 'northing' and another an 'easting' - map
grid references.

I would like the results returned to be ordered with the numbers
'closest' to the given northing and easting combing first.

my query is

---
SELECT userid,postcode,northing,easting FROM memberpostcodes WHERE
(northing > $min_seek_northing) AND (northing < $max_seek_northing)
AND (easting > $min_seek_easting) AND (easting < $max_seek_easting)
---

Therefore, I cannot 'order by easting' etc - as it'll unfairly load
the results (I'm trying to list the results in order of closeness).

Any ideas?

Joe
Jul 20 '05 #1
3 2294
Joseph Hill wrote:
I would like the results returned to be ordered with the numbers
'closest' to the given northing and easting combing first.


Use the Pythagorean theorem to compute distance between two points:
distance is SQRT(X*X+Y*Y), where X and Y are the differences between the
north and east components of the points. But you can skip the square
root computation, because you don't need it just to sort.

You're trying to compute distance from each row's point to your given
point (e.g. $given_northing,$given_easting).

SELECT userid,postcode,northing,easting
FROM memberpostcodes
WHERE (northing BETWEEN $min_seek_northing AND $max_seek_northing)
AND (easting BETWEEN $min_seek_easting AND $max_seek_easting)
ORDER BY ABS(northing-$given_northing)*ABS(northing-$given_northing)
+ABS(easting-$given_easting)*ABS(easting-$given_easting)

Regards,
Bill K.
Jul 20 '05 #2
"Bill Karwin" <bi**@karwin.com> wrote in message
news:cn********@enews4.newsguy.com...
SELECT userid,postcode,northing,easting
FROM memberpostcodes
WHERE (northing BETWEEN $min_seek_northing AND $max_seek_northing)
AND (easting BETWEEN $min_seek_easting AND $max_seek_easting)
ORDER BY ABS(northing-$given_northing)*ABS(northing-$given_northing)
+ABS(easting-$given_easting)*ABS(easting-$given_easting)


There is a POW function in MySql too.

ORDER BY POW(northing-$given_northing, 2) + POW(easting-$given_easting,
2)
Jul 20 '05 #3
Bill Karwin <bi**@karwin.com> wrote in message news:<cn********@enews4.newsguy.com>...
SELECT userid,postcode,northing,easting
FROM memberpostcodes
WHERE (northing BETWEEN $min_seek_northing AND $max_seek_northing)
AND (easting BETWEEN $min_seek_easting AND $max_seek_easting)
ORDER BY ABS(northing-$given_northing)*ABS(northing-$given_northing)
+ABS(easting-$given_easting)*ABS(easting-$given_easting)


Thanks Bill!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony Johansson | last post by:
This class template and main works perfectly fine. But could be better. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter...
4
by: Deborah V. Gardner | last post by:
I have a field with values like this CO 03-10 CO 03-4 VI 03-8 CO 03-533 I would like these to sort for a report by the first two letters and the digits after the hyphen (-) like this
1
by: S Shulman | last post by:
Hi all I need to know the actual order of the items in the listview control even after the user clicked the column header to re-arrange the order Thank you, Shmuel
4
by: nafri | last post by:
I have array of arrays. I need to arrange them in an increased order of their element 0 Here is what i want. dim InputArray()() = {{2,0,0},{1,0,0},{6,0,0},{3,0,0}} and this is the output...
3
by: tcloud | last post by:
Is there a rule for the order of methods in the RichTextFind method? Through experimentation I found an order of the methods when doing reverse searches. Specifically, when searching reverse,...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
4
by: Frederick Gotham | last post by:
What do you think of the following code for setting and retrieving the value of bytes in an unsigned integer? The least significant bit has index 0, then the next least significant bit has index 1,...
1
by: HaifaCarina | last post by:
these are the loops i used: for (h = 0; h<name.length;h++) { highestOrder = Integer.valueOf(name.charAt(0)); highestName = name; for (int count...
0
by: Xiaode | last post by:
I only manage to do this assignment using combo box anyone has any idea to do this using option box??? Specifications Create a form based application that resembles the above figure. For each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.