从mysql数据集中过滤数据

问题描述 投票:0回答:1

我对数据库和一般的SQL相当陌生。我正在使用MySQL数据库,从这个 场地 关于北京的GPS轨迹,所以按照描述创建了这些表格。

CREATE TABLE `plt` (
  `directory` varchar(10) DEFAULT NULL,
  `latitude` double DEFAULT NULL,
  `longitude` double DEFAULT NULL,
  `flag` int(11) DEFAULT NULL,
  `altitude` double DEFAULT NULL,
  `passeddate` varchar(255) DEFAULT NULL,
  `gpsdate` date DEFAULT NULL,
  `gpstime` time DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `plt_distinct` (
  `directory` varchar(10) NOT NULL DEFAULT '',
  `latitude` double NOT NULL DEFAULT '0',
  `longitude` double NOT NULL DEFAULT '0',
  `flag` int(11) DEFAULT NULL,
  `altitude` double NOT NULL DEFAULT '0',
  `passeddate` varchar(255) DEFAULT NULL,
  `gpsdate` date NOT NULL DEFAULT '0000-00-00',
  `gpstime` time NOT NULL DEFAULT '00:00:00',
  `gpsdatetime` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`directory`,`latitude`,`longitude`,`gpsdate`,`gpstime`,`altitude`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `labels` (
  `directory` varchar(10) NOT NULL DEFAULT '',
  `starttime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `endtime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `transportationmode` varchar(10) NOT NULL DEFAULT '',
  PRIMARY KEY (`directory`,`starttime`,`endtime`,`transportationmode`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

我这里是我目前这些表格中的内容。

mysql> SELECT * FROM plt_distinct LIMIT 5;
+-----------+----------+-----------+------+----------+------------+------------+----------+---------------------+
| directory | latitude | longitude | flag | altitude | passeddate | gpsdate    | gpstime  | gpsdatetime         |
+-----------+----------+-----------+------+----------+------------+------------+----------+---------------------+
| 000       |        0 | 39.999686 |  116 |        0 | 164        | 0000-00-00 | 00:20:08 | 0000-00-00 00:00:00 |
| 000       |        0 | 39.999693 |  116 |        0 | 164        | 0000-00-00 | 00:20:08 | 0000-00-00 00:00:00 |
| 000       |        0 | 39.999702 |  116 |        0 | 163        | 0000-00-00 | 00:20:08 | 0000-00-00 00:00:00 |
| 000       |        0 | 39.999703 |  116 |        0 | 162        | 0000-00-00 | 00:20:08 | 0000-00-00 00:00:00 |
| 000       |        0 | 39.999709 |  116 |        0 | 165        | 0000-00-00 | 00:20:08 | 0000-00-00 00:00:00 |
+-----------+----------+-----------+------+----------+------------+------------+----------+---------------------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM labels LIMIT 5;
+-----------+---------------------+---------------------+--------------------+
| directory | starttime           | endtime             | transportationmode |
+-----------+---------------------+---------------------+--------------------+
| 010       | 2007-06-26 11:32:29 | 2007-06-26 11:40:29 | bus                |
| 010       | 2008-03-28 14:52:54 | 2008-03-28 15:59:59 | train              |
| 010       | 2008-03-28 16:00:00 | 2008-03-28 22:02:00 | train              |
| 010       | 2008-03-29 01:27:50 | 2008-03-29 15:59:59 | train              |
| 010       | 2008-03-29 16:00:00 | 2008-03-30 15:59:59 | train              |
+-----------+---------------------+---------------------+--------------------+
5 rows in set (0.00 sec)

然后我想统计一下每个GPS点的数量 transportationmode. 我怎么做这样做呢?

mysql aggregate geospatial
1个回答
-1
投票

Kindly make it more.post your expected output data also.As i know u can use this query .

SELECT count(directory) as total_transportationmode from labels GROUP BY labels total_transportationmode 。

© www.soinside.com 2019 - 2024. All rights reserved.