zoukankan      html  css  js  c++  java
  • mysql优化

    记住不要出现查询order by,这样严重影响效率,当然除了最后可以出现

    DATEDIFF是日期相减得到天数

    DATE_FORMAT对日期格式化

    DATEDIFF(DATE_FORMAT(NOW(),'%Y-%m-%d'), DATE_FORMAT(should_repay_date,'%Y-%m-%d'))  AS should_repay_day

    统计记录数使用count(1),不要用count(*)

    select count(1) from user

    查询字段不要用* 代替所有的,要查那些字段就查那些字段

    select username, password from user

    实现先排序后分组,不要用下面这个语句,外表查询每一条记录都会从内表遍历一遍,速度非常慢

    select id, username, password, age from 

    (

    select id, username, password, age from user order by age

    ) temp group by age

    优化后

    select t1.id, t1.usernam, t1.password, t1.age from user t1

    inner join 

    (select id, max(age) as maxAge from user group by age ) b on t1.id = b.id and t1.age = b.maxAge


  • 相关阅读:
    第一个Servlet项目(IDEA)
    Web交互基本流程以及HTTP协议详解
    mybatis中Mapper.xml配置详解
    认识mybatis
    SpringAOP
    Spring AOP
    70. Climbing Stairs
    位运算
    Leetcode分类
    21. Merge Two Sorted Lists
  • 原文地址:https://www.cnblogs.com/handsome1013/p/5898791.html
Copyright © 2011-2022 走看看