标签:
数据库的优化主要包括两个方面,一方面是SQL程序语句的优化,另一方面是数据库服务器和配置的优化。查询语句优化主要涉及两个方面:一些普遍遵循的原则,以及怎样对查询语句进行性能分析。
SELECT * FROM t WHERE YEAR(d) >= 2011;
SELECT * FROM t WHERE d >= ‘2011-01-01’;
SELECT * FROM a JOIN b ON a.id = b.id LEFT JOIN c ON c.time = a.date LEFT JOIN d ON c.pid = b.aid LEFT JOIN e ON e.cid = a.did
SELECT * FROM t WHERE name LIKE ‘%de%’
SELECT * FROM t WHERE name >= ‘de’AND name <= ‘df’
SELECT * FROM Member;
SELECT id,name,pwd FROM Member;
INSERT INTO t(id,name)VALUES(1,’a’); INSERT INTO t(id,name)VALUES(2,’b’); INSERT INTO t(id,name)VALUES(3,’c’);
INSERT INTO t(id,name)VALUES(1,’a’),(2,’b’),(3,’c’);
SELECT * FROM article AS article RODER BY id LIMIT 1000000,10;
SELECT * FROM article AS article WHERE id BETWEEN 1000000 AND 1000010 RODER BY id;
select * from table order by rand() limit 20;
Select * from ‘table’as t1 join(select rand(rand() * ((select max(id) from ‘table’)-(select min(id) from ‘table’))+(select min(id) from ‘table’))as id) as t2 where t1.id >= t2.id order by t1.id limit 1;
标签:
原文地址:http://www.cnblogs.com/chenqionghe/p/4760451.html