mysql索引、查询连接、文本函数、窗口函数、时间函数

目录

1、索引

1.1 创建索引

1.2 删除索引

2、查询连接 :Union all和Union

3、表结构操作

4、排序

5、判断语句

5.1  if

5.2  case when ……then

6 常用函数

6.1  文本函数

6.2  时间函数

6.3 窗口函数

6.3.1  row_number() over()窗口函数

7 数学函数

8 数字类型转换函数

9 存储过程


1、索引

1.1 创建索引

 CREATE 
| UNIQUE -- 唯一索引
| FULLTEXT -- 全文索引
| INDEX   index_name   ON table_name -- 不指定唯一或全文时默认普通索引
 (column1[(length) [DESC|ASC]] [,column2,...]) -- 可以对多列建立组合索引  

create index idx_duration ON examination_info(duration);  --创建普通索引
create unique index uniq_idx_exam_id ON examination_info(exam_id);  --创建唯一索引
create fulltext index full_idx_tag ON examination_info(tag);   --创建全文索引

1.2 删除索引

alter table table_name drop index 索引名

alter table examination_info drop index uniq_idx_exam_id;
alter table examination_info drop index full_idx_tag;

2、查询连接 :Union all和Union

Union all对两个数据集(两张表)合并,不去重,保留所有,合并时字段类型要保持一致

Union对两个数据集合并,并自动去重

select id,name
from OrderItems1
union 
select id,name
from OrderItems2;

在用 UNION 组合查询,结果要排序时,最后一个select后面接order by排序

select id,name
from OrderItems1
union 
select id,name
from OrderItems2 order by id;

3、表结构操作

基本语法:alter table table_name 操作名 column 列名[列名2]  类型和长度 [after|first 列名];

如:添加一列在某一列的后面

alter table user_info add column school varchar(15) after level;

改名并修改数据类型和长度:对job进行改名,并更改数据类型和长度

alter table user_info change column job profession varchar(10);

修改默认值

alter table user_info modify column achievement int(11) default 0;

4、排序

order by 字段名 desc;  --结果降序(从大到小)
order by 字段名 asc;   --结果升序(不写asc,系统默认为升序)ÿ
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值