什么是point类型数据?举个例子如下:POINT(123.462202 41.804471)
首先建立一个表:
DROP TABLE IF EXISTS `tb_point`;
CREATE TABLE `tb_point` (
`timestamp` date NOT NULL COMMENT '时间戳',
`point` point NOT NULL COMMENT '经纬度',
`type` char(20) character set utf8 default '' COMMENT '点类型',
`name` varchar(50) character set utf8 NOT NULL COMMENT '点名称',
`introduce` text character set utf8 COMMENT '介绍,包含文字、视频、目录,json格式',
`attention` int(5) NOT NULL default '0' COMMENT '关注人数',
`score` tinyint(2) NOT NULL default '0' COMMENT '评分,用于协同过滤推荐',
`status` tinyint(2) NOT NULL default '2' COMMENT '状态,用于管理员添加',
`uri` varchar(255) character set utf8 default NULL COMMENT '维基uri',
PRIMARY KEY (`timestamp`,`point`(25)),
KEY `index_timestamp` USING BTREE (`timestamp`),
KEY `index_name` USING HASH (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
要想使用point类型,在建表时,需要这样设置:ENGINE=MyISAM
建完表以后插入部分数据。插入数据后的部分截图如下(其中红框里就是point类型数据):
insert示例:
INSERT INTO `tb_point` VALUES ('1900-01-01', GeomFromText('POINT(123.462202 41.804471)'), '景点', '沈阳故宫',
'{\"text\":\"1900年左右的沈阳故宫文字介绍\",\"picture\":\"\",\"video\":\"\"}', '1000', '0', '1', null);
select示例:
SELECT timestamp,AsText(point),type,name,introduce,attention,score,uri FROM
tb_point order by AsText(point),`timestamp` DESC ;
select的结果如下图所示: