0

运行此查询时出现以下错误:

SELECT count(*) AS COUNT,
       ((ACOS(SIN(
        (SELECT latitude
         FROM cities
         WHERE name = 'london' & country = 'gb')*PI()/180) * 
         SIN((cities.latitude)*PI()/180)+COS(                                                                                                      
 (SELECT latitude
  FROM cities
  WHERE name = 'london' && country = 'gb')*PI()/180)*COS((cities.latitude)*PI()/180)*COS((
(SELECT longitude
 FROM cities
 WHERE name = 'london' && country = 'gb')-
(cities.longitude))*PI()/180))*180/PI())*60*1.1515) AS distance
FROM tbl_products
LEFT JOIN members ON tbl_products.seller = members.id
LEFT JOIN business ON tbl_products.seller = business.bid
INNER JOIN cars ON tbl_products.prod_id = cars.prod_id
LEFT JOIN car ON cars.car = car.id
LEFT JOIN cities ON members.location = cities.id
LEFT JOIN regions ON cities.region = regions.code && cities.country = regions.country
WHERE tbl_products.title LIKE '%|mazda%' ESCAPE '|'
OR tbl_products.description LIKE '%|mazda%' ESCAPE '|' && regions.country = 'gb' HAVING distance <= '30';

子查询返回超过 1 行。

我只是想知道如何在给定距离内检索记录。

4

1 回答 1

0

该错误准确地表明了它所说的内容。你正在做一个子查询,但它返回多行,在一个只需要一行的上下文中

SELECT count*(*) AS count, ACOS(SIN(...subselect here ...))

很难说出你正在做的子选择中的哪个导致了这种情况,但你必须找到哪一个,并让它只发回一行。而且由于您在进一步的函数调用中使用结果,您还必须确保只返回一个 FIELD ,例如

SELECT sin(select 1,2 from dual) from dual

会导致相关错误。

于 2013-05-27T18:13:57.380 回答