Mysql视图不能在from语句中有子查询

时间:2015-02-24 01:09:42

标签: mysql gps

我知道之前已经问过这个问题,但我无法弄清楚如何重新安排我的查询。

基本上我有一个数据库,每秒都会使用DD中的当前GPS位置进行更新。我有另一个数据库,其中包含一些DMS格式的位置。我需要做的是创建一个视图,将当前位置与其他数据库连接起来,这样用户就可以查询一个表并获得与该位置相关的结果。我无法将位置输入数据库查询,我必须使用GPS位置。

我在下面有qorking查询。

select * from(select("") as nav_non, latitude as current_lat, longitude as current_lon from navtime.gps_data order by id desc limit 1) nav left join(select * , ("") as sel_non,
  if (substring(loc, 7, 1) = 'N', round(((substring(loc, 1, 2) * 3600000) + (substring(loc, 3, 2) * 3600000 / 60) + (substring(loc, 5, 2) * 3600000 / 60 / 60)) / 1e7, 6), round(((substring(loc, 1, 2) * 3600000) + (substring(loc, 3, 2) * 3600000 / 60) + (substring(loc, 5, 2) * 3600000 / 60 / 60)) / 1e7, 6) * -1) as `latitude`,

    if (substring(loc, 16, 1) = 'E', round(((substring(loc, 8, 4) * 3600000) + (substring(loc, 12, 2) * 3600000 / 60) + (substring(loc, 14, 2) * 3600000 / 60 / 60)) / 1e7, 6), round(((substring(loc, 8, 4) * 3600000) + (substring(loc, 12, 2) * 3600000 / 60) + (substring(loc, 14, 2) * 3600000 / 60 / 60)) / 1e7, 6) * -1) as `longitude`
  from ssd.sel where length(loc) = '16') sel on nav.nav_non = sel.sel_non where `longitude`
between `current_lon` - 200 / abs(cos(radians(`current_lon`)) * 69) and `current_lon` + 200 / abs(cos(radians(`current_lon`)) * 69) and `latitude`
between `current_lat` - (200 / 69) and `current_lat` + (200 / 69)

这是数据库

--
-- Database: `navtime`
--
CREATE DATABASE `navtime` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `navtime`;

CREATE TABLE IF NOT EXISTS `gps_data` (
  `id` int(11) NOT NULL,
  `latitude` double(11,6) NOT NULL,
  `longitude` double(11,6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `gps_data` (`id`, `latitude`, `longitude`) VALUES
(2016, 10.534520, -43.345310);
--
-- Database: `ssd`
--
CREATE DATABASE `ssd` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `ssd`;

CREATE TABLE IF NOT EXISTS `sel` (
  `id` int(11) NOT NULL,
  `loc` varchar(255) NOT NULL,
  `data1` text NOT NULL,
  `data2` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


INSERT INTO `sel` (`id`, `loc`, `data1`, `data2`) VALUES
(10, '351224N 1231212W', 'test data1', 1),
(11, '351224N 0931212W', 'test data1', 1),
(12, '351224N 0931122E', 'test data1', 2),
(13, '351214N 0951122E', 'test data3', 3),
(13, '351214N 1451122E', 'test data3', 3);

0 个答案:

没有答案