个人常用sql语句记录
2017-01-22 17:23
363 查看
【给网页上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%";
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%";
相关文章推荐
- 记录SQL常用语句 不定期修改
- SQL SERVER常用取重复记录的SQL语句
- mysql建表常用sql语句个人经验分享
- 常用几种数据库,取前10条记录的sql语句写法
- 个人收集的一些常用的sql查询语句与函数
- 常用SQL语句记录
- mysql建表常用sql语句个人经验分享
- Oracle常用SQL语句记录单
- 常用判断重复记录的SQL语句
- 记录常用的sql语句
- 常用SQL语句记录
- 常用几种数据库,取前10条记录的sql语句写法
- 不常用到的sql语句记录
- 常用几种数据库,取前10条记录的sql语句写法
- SQL SERVER常用取重复记录的SQL语句
- sql常用语句记录
- sql常用语句记录
- 记录下最近项目中常用到的SQL语句
- 个人常用的sql脚本语句
- GIS应用开发中常用的SQL语句(分组排序取前几条记录)