摘要: 表的创建 CREATE TABLE `lee` (`id` int(10) NOT NULL AUTO_INCREMENT, `name` char(20) DEFAULT NULL, `birthday` datetime DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 数据插入: insert into lee(name,birthday) values ('sam','1990-01-01'); insert into lee(name,birthday) value 阅读全文
posted @ 2013-11-29 14:41 longailili 阅读(340) 评论(0) 推荐(0)
摘要: 语句一:select count(*) from A where A.a not in (select a from B)语句二:select count(*) from A left join B on A.a = B.a where B.a is null语句三:select count(*) from A where not exists (select a from B where A.a = B.a)知道以上三条语句的实际效果是相同的已经很久了,但是一直没有深究其间的效率对比。一直感觉上语句二是最快的。 今天工作上因为要对一个数千万行数据的库进行数据清除,需要删掉两千多万行数据。大量 阅读全文
posted @ 2013-11-29 14:36 longailili 阅读(700) 评论(0) 推荐(0)
摘要: select * from test where id in(3,1,5) order by find_in_set(id,'3,1,5'); select * from test where id in(3,1,5) order by substring_index('3,1,2',id,1); 偶尔看到的。。。或许有人会注意过,但我以前真不知道 SQL: select * from table where id IN (3,6,9,1,2,5,8,7);这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序的,但如果我们真要按IN里面的 阅读全文
posted @ 2013-11-29 14:32 longailili 阅读(318) 评论(0) 推荐(0)