SQL 语句

--删除address表中重复>5

delete from address where select count(street.[street_name]) x, street.[street_name], street.[latitude], street.[longitude] From street group by street.[street_name]) a
where a.x>5

--创建表
 Create  TABLE address(
[_id] integer PRIMARY KEY AUTOINCREMENT
,[street_name] varchar(1024)
,[latitude] double NOT NULL
,[longitude] double NOT NULL
  
);

--插入数据
insert into address(street_name, latitude, longitude)
      select street.[street_name], street.[latitude], street.[longitude] From street;

--删除数据
delete from address where _id not in
 (select min(_id) from address group by street_name) and (select max(_id)from address group by street_name);

--查询
 select count(street_name) from address;

--三表合一

select tags.[value] , b_table.a2 , b_table.a3
        from tags,
               (Select a_table.point a1, node.[latitude] a2, node.[longitude] a3, a_table.identify a4
                          from node, (
                                select ways.[node] point, ways.[id] identify from ways where ways.[ord] = '0') a_table
                                     where node.[id] = a_table.point) b_table
                                            where tags.[id] = b_table.a4;                                                   


select * from (
select tags.[value] street_name, node.[latitude], node.[longitude]
from  node, tags, ways
where ways.[node]=node.[id] and tags.[id]=ways.[id] and ways.[ord]='0')  a
where a.street_name like '%街%';


Select count(y.xll) From (
select x.ll xll from (
select tags.[value] ll, b_table.a2 , b_table.a3
        from tags,
               (Select a_table.point a1, node.[latitude] a2, node.[longitude] a3, a_table.identify a4
                          from node, (
                                select ways.[node] point, ways.[id] identify from ways where ways.[ord] = '0') a_table
                                     where node.[id] = a_table.point) b_table
                                            where tags.[id] = b_table.a4 ) x group by x.ll) y ;

 

加载文件到数据库

sql="load data local infile '#{file}' into table cities fields terminated by ',' enclosed by '\"'  lines terminated by '\n'(name,id) "

 

update [table] set [com]= (SELECT count(*) FROM [table] where [com] like "%[]%") where name="[]" and [com]="[]"

你可能感兴趣的:(sql语句)