尽管声明了MySQL列未找到?

时间:2015-05-29 11:50:58

标签: mysql select

此查询有效:

import java.util.Scanner;
public class TheatreSquare {
private static Scanner input;
public static void main(String[] args) {
    input = new Scanner(System.in);
    double m=input.nextDouble();
    double n=input.nextDouble();
    double a=input.nextDouble();
    long i=(long)(m/a);
    long j=(long)(n/a);

    if((a*a*i*j) <m*n){
        if(a*i < m){
            //to check weather it is entering if()
            i+=1;
        }
        if(a*j < n ){
            //to check weather it is entering if()
            j+=1;
        }
       }
    System.out.println((long)(i*j));
}
}

但是,此查询会抛出“未找到列select d.*, (6371 * 3.1415926 * SQRT((:lat - dl.lat) * (:lat - dl.lat) + COS(:lat / 57.2957795) * COS(dl.lat / 57.2957795) * (:long - dl.long) * (:long - dl.long)) / 180) as xdistance from `dudes` as d left join `dude_locations` as dl on (dl.id_dude = d.id) where (6371 * 3.1415926 * SQRT((:lat - dl.lat) * (:lat - dl.lat) + COS(:lat / 57.2957795) * COS(dl.lat / 57.2957795) * (:long - dl.long) * (:long - dl.long)) / 180) <= dl.distance group by d.id limit 20 ”错误:

xdistance

我所要做的就是这样做,所以同样的计算不会两次。这可能吗?

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

where 
d.xdistance <= dl.distance

答案 1 :(得分:1)

您想要的查询可能是这样的:

select d.*,
       MIN((6371 * 3.1415926 * SQRT((:lat - dl.lat) * (:lat - dl.lat) + COS(:lat / 57.2957795) * COS(dl.lat / 57.2957795) * (:long - dl.long) * (:long - dl.long)) / 180) ) as xdistance
from `dudes` as d left join
     `dude_locations` as dl
     on (dl.id_dude = d.id)
group by d.id
having xdistance <= min(dl.distance)
limit 20;