标签:mysql写出高质量的sql语句的几点建 高质量的sql语句
CleverCode在实际的工作也写过一些低效率的sql语句。这些语句会给数据库带来很大的压力,最主要的表现就是sql语句运行慢,后来逐渐的去优化和尝试。总结了一些高质量的sql语句的写法。这里CleverCode总结一下分享给大家。
【 CleverCode发表在csdn博客中的原创作品,请勿转载,原创地址:http://blog.csdn.net/clevercode/article/details/46341147】
select * from system_user where date(createtime) >= '2015-06-01'优化后:
select * from system_user where createtime >= '2015-06-01'
select * from system_user where age + 10 >= 20优化后:
select * from system_user where age >= 10
select * from table_a a left join table_b b on a.id = b.id left join table_c c on a.id = c.id where a.id > 100 and b.id < 200
select * from ( select * from table_a where id > 100 ) a left join( select * from table_b where id < 200 )b on a.id = b.id left join table_c on a.id = c.id
select * from system_user where age > 10优化后:
select username,email from system_user where age > 10
insert into system_user(username,passwd) values('test1','123456') insert into system_user(username,passwd) values('test2','123456') insert into system_user(username,passwd) values('test3','123456')
insert into system_user(username,passwd) values('test1','123456'),('test2','123456'),('test3','123456')
标签:mysql写出高质量的sql语句的几点建 高质量的sql语句
原文地址:http://blog.csdn.net/clevercode/article/details/46341147