473,809 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,easti ng FROM memberpostcodes WHERE
(northing > $min_seek_north ing) AND (northing < $max_seek_north ing)
AND (easting > $min_seek_easti ng) AND (easting < $max_seek_easti ng)
---

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 2320
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,easti ng
FROM memberpostcodes
WHERE (northing BETWEEN $min_seek_north ing AND $max_seek_north ing)
AND (easting BETWEEN $min_seek_easti ng AND $max_seek_easti ng)
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.co m> wrote in message
news:cn******** @enews4.newsguy .com...
SELECT userid,postcode ,northing,easti ng
FROM memberpostcodes
WHERE (northing BETWEEN $min_seek_north ing AND $max_seek_north ing)
AND (easting BETWEEN $min_seek_easti ng AND $max_seek_easti ng)
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.co m> wrote in message news:<cn******* *@enews4.newsgu y.com>...
SELECT userid,postcode ,northing,easti ng
FROM memberpostcodes
WHERE (northing BETWEEN $min_seek_north ing AND $max_seek_north ing)
AND (easting BETWEEN $min_seek_easti ng AND $max_seek_easti ng)
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
1715
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 in the class template so I know how many references I have to the body. In my case it's the Integer wrapper class which is the body. This template works for many different types. The one that I use is named Integer and is a Wrapper for an int....
4
8918
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
1143
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
1865
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 outputArray()() = {{1,0,0},{2,0,0},{3,0,0},{6,0,0}} Has any body got any idea how to it.
3
2376
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, with matching case and for whole words, the statement must be in this order to work correctly: -- RichTextBoxFinds.Reverse.MatchCase.WholeWord I thought each option was ORed together and their order wasn't important,
104
10907
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 sorted by Numb. Everything I've read on the web suggests that including the TOP directive should enable ORDERY BY in views. Does someone have an idea why the sorting is not working correctly for this particular view? thanks. CREATE VIEW...
4
2215
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, and so on. The code computes at runtime the byte-order of the unsigned integer, but alas it would be better if it could be determined at compile-time. The code potentially invokes undefined behaviour if an unsigned integer contains padding bits....
1
8776
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; count<name.length;count++) { if (Integer.valueOf(name.charAt(0)) < highestOrder)
0
1422
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 order, the user selects one main course item and zero or more of the associated add-ons. When the user clicks on the Place Order button, the application displays the sub total, tax, and total due for the order. It also enables the Print Receipt...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.