English 中文(简体)
MySQL - 环绕数字
原标题:mySQL - Wrap Around Numbers

我有一个从0,0到799,799(800x800个街区)的网格。我有一个问题,我无法把头放在这个问题上,一个指导或帮助提示会很好。只要它出现在所说的网格中,我就能得到结果,但是,在环绕网格时,它不会给我结果。

(这样我就能毫无问题地得到结果):

SELECT * FROM map WHERE ((xaxis >= 0 AND xaxis <= 10) AND (yaxis >= 0 AND yaxis <= 10))

如果我尝试(环绕网格) :

SELECT * FROM map WHERE ((xaxis >= 795 AND xaxis <= 10) AND (yaxis >= 795 AND yaxis <= 10))

我怎样去修补它呢?如果有任何指导或指向正确方向,我将不胜感激。

提前感谢!

最佳回答

您的第二个查询 :

SELECT * FROM map WHERE ((xaxis >= 795 AND xaxis <= 10) AND (yaxis >= 795 AND yaxis <= 10))

将不给您任何结果, 因为 xaxis 不能是 & gt; = 795 和 & lt; = 10( 类似 yexis) 。

要绕圈,您需要使用剩余函数或模量函数,例如:

SELECT * FROM map WHERE ((MOD(799,xaxis-1)>0 AND xaxis <= 10) AND (MOD(799,yaxis-1)>0 AND yaxis <= 10))
问题回答

在别人的帮助下找到了答案 假设我放在这里 是为了让别人受益

$input_left_x     = (($XCoord - $Miles + 800) % 800);
$input_right_x    = (($XCoord + $Miles) % 800);
$input_left_y     = (($YCoord - $Miles + 800) % 800);
$input_right_y    = (($YCoord + $Miles) % 800);

SELECT * FROM map
WHERE MOD( xaxis - COALESCE(".$input_left_x." , 0) + 800 , 800 )
BETWEEN 0 AND MOD( COALESCE(".$input_right_x." , 799) - COALESCE(".$input_left_x." , 0) + 800 , 800 )
AND MOD( yaxis - COALESCE(".$input_left_y." , 0) + 800 , 800 )
BETWEEN 0 AND MOD( COALESCE(".$input_right_y." , 799) - COALESCE(".$input_left_y." , 0) + 800 , 800 )




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签