标签:order first 条件 nbsp 长度 数据库 关联 针对 rom
1 # 列是表达式的一部分 2 select * 3 from application as a 4 where a.id + 1 = 5000
5 # 列是函数的参数 6 select * 7 from application as a 8 where date(a.created_at) = ‘20181010‘ 9 10 # 含有隐式转换(user_id 为int类型) 11 select * 12 from application as a 13 where a.user_id = ‘567‘
1 select * 2 from application as a 3 where a.name = ‘%xia%‘ 4 注:以上不能使用索引针对单列索引。对于复合索引,索引中对应列前面的列依旧可以使用索引。
1、必须符合最左前缀要求
1 # 现有复合索引 cycle、sex、status 2 3 select * 4 from application as a 5 where a.status = 2 6 and a.sex = ‘male‘ 7 # 不符合最左前缀原则,无法使用复合索引
8 注:针对此问题,如果字段对应值较少,可列出字段所有值,从而利用索引 9 10 # 现有索引 sex、cycle、status 11 select * 12 from application as a 13 where a.sex in(‘male‘, ‘female‘) 14 and a.cycle = 2 15 and a.status = 4
1 # 现有复合索引sex、cycle、status 2 3 select * 4 from application as a 5 where a.sex = ‘male‘ 6 and a.cycle > 2 7 and a.status = 3 8 # 复合索引中的第二列使用了范围查询,第三列status无法再使用索引 9 注:多个等值查询无此限制,即in无次限制 10
# 现有复合索引sex、cycle、status 11 12 select * 13 from application as a 14 where a.sex = ‘male‘ 15 and a.cycle in(3, 4) 16 and a.status = 3 17 # 使用in代替范围查询
1 # 现有索引cycle、status 2 3 select * 4 from application as a 5 order by a.cycle, a.status desc 6 # cycle 与 status 的排列顺序不同,无法使用索引排序
1 # 现有索引application.cycle, auto_cal_list.status 2 3 select * 4 from application as a 5 inner jion auto_call_list as l on a.id = l.application_id 6 where a.status = 4 7 order by a.cycle, l.status 8 # order by子句有第二个
1 select * from product where actor = ‘SE‘ and title like ‘%AP%‘ 2 3 select * from product join(select pro_id from product where actor = ‘SE‘ and title like ‘%AP%‘ )as t1 on t1.prod_id = product.prod_id
1 select * 2 from application as a 3 4 select a.id, a.user_id 5 from application as a
1 Application.filter().limit(1).execute() 2 3 Application.filter().first()
标签:order first 条件 nbsp 长度 数据库 关联 针对 rom
原文地址:https://www.cnblogs.com/yuluodisuihe/p/9795181.html