douzhigan1687 2014-11-30 03:58 采纳率: 0%
浏览 32
已采纳

如何正确子查询 - 或者这是怎么回事? [关闭]

I'm trying to fetch a load of database entries which include geo data that has to be fetched from another table. When i try to run a custom distance function on them it causes an error, I have tried to include it as a sub query but that does not seem to work either (The function does work).

$bsns = $this->db->select('businesses.name, businesses.about')
                            ->select('postcodes.postcode, postcodes.lat AS lat, postcodes.long AS long')
                            ->select('industries.name')
                            ->select('get_distance_in_miles_between_geo_locations('.$geo['lat'].', '.$geo['long'].', lat, long) AS distance', null, false)
                            ->from('businesses')
                            ->join('postcodes', 'postcodes.postcode = businesses.postcode', 'left')
                            ->join('industries', 'industries.IN_ID = businesses.industry', 'left')
                            ->order_by('distance', 'ASC')
                            ->get(); 

This is the code i'm using at the moment, The error:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long, `industries`.`name`, get_distance_in_miles_between_geo_locations(50.344178' at line 1

New error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'businesses`) LEFT JOIN `postcodes` ON `postcodes`.`postcode` = `businesses`.`pos' at line 1

SELECT `businesses`.`name`, `businesses`.`about`, `postcodes`.`postcode`, `postcodes`.`lat`, `postcodes`.`long`, `industries`.`name`, get_distance(50.344178, `-4`.`757147`, `lat`, `long`)` AS distance FROM (`businesses`) LEFT JOIN `postcodes` ON `postcodes`.`postcode` = `businesses`.`postcode` LEFT JOIN `industries` ON `industries`.`IN_ID` = `businesses`.`industry` ORDER BY `distance` ASC
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 echarts地图添加点击事件
      • ¥15 不知道带什么标题好随便搞一个吧
      • ¥15 ffmpeg 图片合成视频
      • ¥15 软科大学爬取获取所有数据
      • ¥15 如何修改损失函数以及代码讲解
      • ¥15 有偿咨询!!程序的小数点怎么取到后四位啊!
      • ¥15 IRS智能反射面相关文章代码
      • ¥15 landsat5的两幅影像镶嵌前波段是123457,为什么镶嵌后波段变成了123456?
      • ¥15 关于#matlab#中fmincon函数如何处理约束问题?
      • ¥60 Java程序,控制台输出