explain select tid from test01 where tid =1 ; alter table test01 drop primary key ; create index test01_index on test01(tid) ; eq_ref:唯一性索引:对于每个索引键的查询,返回匹配唯一行数据(有且只有1个,不能多 、不能0) select ... from ..where name = ... .常见于唯一索引 和主键索引。
select distinct(field_name) from table_name; 1. 实现简单的数学四则运算: select 1*2; select 10 MOD 3; select field_name*2 from table_name; 1. 2. 3. 实现字符串连接: select concat("hello","world"); select concat(concat(filed_name,"is"),name) from table_name; 1. 2. 带条件查询:...
explain select t.tname,tc.tcdesc from teacher t,teacherCard tc where t.tcid=tc.tcid and t.tid=(select c.tid from course c where cname='sql'); 结果如下: 结论:id值有相同,又有不同。id值越大越优先;id值相同,从上往下顺序执行。 2)select_type关键字的使用说明:查询类型 ① simple:简单查...
id是执行计划的标识符,是SELECT 查询的序号。如果结果集会跟其他表的结果用UNION关键字相结合,那么id可能为空。 id是否为空,对执行计划的影响不大。 select_type select_type表示sql语句查询的类型。具体表示如下表: table 输出行引用的表的名称。一般为表格名称或别名,也可能为如下值: 1.UNION的并集结果集。 2...
2)select_type关键字的使用说明:查询类型 ① simple:简单查询 不包含子查询,不包含union查询。 explain select * from teacher; 结果如下: ② primary:包含子查询的主查询(最外层) ③ subquery:包含子查询的主查询(非最外层) ④ derived:衍生查询(用到了临时表) ...
mysql>explainselecta.idfromt1asainnerjoint2asbona.id=b.id;+---+---+---+---+---+---+---+---+---+---+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+---+---+---+---+---+---+---+---+---+---...
select substr(event_time,1,10) as login_date ,user_id fromlogin_user where dt between '20230401' and '20230430' and event_type like '%login%' and is_success=1 and user_id is not null group by login_date,user_id 2、用户分组,登录日期倒序排序后,根据偏移窗口函数,找出每个日期后两行数据...
比如:SELECT * FROM t2 WHERE t2.key2 IN ( SELECT id FROM t3 WHERE t2.key2 = t3.key2 ) OR t2.key2 = 1;通过查看MySQL优化的执行sql,可以看到MySQL将in子查询优化为了exist语句,并且在主键索引上进行了等值查询。MySQL优化后的语句:/* select#1 */ select `dbs`.`t2`.`id` AS `id`,`...
{column-list} 是一个或多个表列(称为 {column})的逗号分隔列表。 不明确列可能进一步限定为 {tablename.column}。 星号可用作 SELECT 查询中的列列表,以表示引用表中的所有列。 按列位置引用字段时,按名称而不是使用星号选择列。 星号不能用作 INSERT INTO 查询中的列列表。