您的位置:首页 > 数据库

个人常用sql语句记录

2017-01-22 17:23 323 查看
【给网页上POI点做准备】

select c.id as '充电站id',ci.id as '景点id',c.poi_id,c.poi_id,c.name,c.location_lon,c.location_lat,

replace(GROUP_CONCAT(CONCAT(ci.location_lon,',',ci.location_lat,';')),';,',';')

from poi_shanghai_charging_loc as c,poi_shanghai_scenic_loc as ci

where (c.location_lon > ci.location_lon-0.005 and  

c.location_lon < ci.location_lon+0.005 and

c.location_lat > ci.location_lat-0.005 and

c.location_lat < ci.location_lat+0.005 ) 

group by c.id;

【POI点加上信息】

select c.id as '充电站id',ci.id as '景点id',c.poi_id,c.poi_id,c.name,ci.name,

concat(ci.name,',',group_concat(c.name)),

concat(CONCAT(ci.location_lon,',',ci.location_lat),';',replace(GROUP_CONCAT(CONCAT(c.location_lon,',',c.location_lat,';')),';,',';')) 

from poi_shanghai_charging_loc as c,poi_shanghai_scenic_loc as ci

where (c.location_lon > ci.location_lon-0.01 and  

c.location_lon < ci.location_lon+0.01 and

c.location_lat > ci.location_lat-0.01 and

c.location_lat < ci.location_lat+0.01 ) 

group by ci.id;

精简↓

select ci.id as '图书馆id',ci.poi_id,ci.name,

concat(ci.name,',',group_concat(c.name)),

concat(CONCAT(ci.location_lon,',',ci.location_lat),';',replace(GROUP_CONCAT(CONCAT(c.location_lon,',',c.location_lat,';')),';,',';')) 

from poi_shanghai_charging_loc as c,poi_shanghai_scenic_loc as ci

where (c.location_lon > ci.location_lon-0.01 and  

c.location_lon < ci.location_lon+0.01 and

c.location_lat > ci.location_lat-0.01 and

c.location_lat < ci.location_lat+0.01 ) 

group by ci.id;

CREATE TABLE `NewTable` (

`id`  int(11) NOT NULL AUTO_INCREMENT ,

`dianping_id`  int(11) NULL DEFAULT NULL ,

`shop_name`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,

`shop_lv`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,

`shop_ave_price`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,

`shop_comment_count`  int(11) NULL DEFAULT NULL ,

`shop_type`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,

`shop_area`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,

`shop_addr`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,

`taste`  double NULL DEFAULT NULL ,

`env`  double NULL DEFAULT NULL ,

`service`  double UNSIGNED NULL DEFAULT NULL ,

PRIMARY KEY (`id`)

)

ENGINE=MyISAM

DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci

AUTO_INCREMENT=1

CHECKSUM=0

ROW_FORMAT=DYNAMIC

DELAY_KEY_WRITE=0

;

【查找有重复值的项】

select charge_id,count(*) as count from chargelife_info group by charge_id having count>1; 

【搜索结果去重】

Select count(distinct charge_id) from chargelife_info

【查看默认的编码格式】

show variables like "%char%";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: