摘要: 1. 书写顺序 select->distinct->from->join->on->where->group by->having->order by->limit 2. 执行顺序 from->on->join->where->group by->sum、count、max、avg->having- 阅读全文
posted @ 2022-02-07 21:03 静沐丶暖阳 阅读(966) 评论(0) 推荐(0) 编辑
摘要: 一. 基础调优(从Sql语句角度) 1. 单条记录查询最后添加 limit 1, 避免全表查询; 2. 针对sql执行过长的语句进行explain解析, 再做相应调优; 3. where子句尽量避免: - 表达式; - 对null值判断,建议对null值设置默认值0; - 函数操作; - 使用!=或 阅读全文
posted @ 2022-02-07 20:10 静沐丶暖阳 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 1. 通过关联字段把一张表的字段值更新另一张表的字段值 update table_a a, table_b b set a.username = b.username where a.id = b.id; -- 以下2种更新结果以table_b的查询结果为准,table_b中没有查到的记录会全部被更 阅读全文
posted @ 2022-02-07 16:37 静沐丶暖阳 阅读(69) 评论(0) 推荐(0) 编辑
摘要: 1.<if> <select id="" parameterType="" resultType=""> select * from user where 1 = 1 <if test="username != null"> and username = #{username} </if> <if 阅读全文
posted @ 2022-02-07 10:46 静沐丶暖阳 阅读(263) 评论(0) 推荐(0) 编辑