mysql基本语法

一、mysql排序


不加任何关键字,默认是按照升序来排序的

排序关键字:desc(降序),asc(升序)

代码:select id,Name,CountryCode,District,Population from city order by Population desc

多字段排序:

select id,Name,CountryCode,District,Population from city order by CountryCode desc,Population asc


二、mysql 通配符

1、%aa%----匹配字符串包含aa的字符串

2、%aa---匹配以aa结尾的字符串

3、aa%-----匹配以aa开头的字符串

4、aa_------匹配字符串aa+任意一个字符

5、去空格函数:rtrim(),ltrim()

mysql字符串匹配忽略大小写问题

三、常用函数


例子:


日期时间函数:


获取当前日期,当前时间

select curdate(),curtime()


获取时间戳形式的日期格式


date()函数:

select date(last_update) from sakila.film where date(last_update)='2006-02-15'


date().year(),month(),datediff()函数


四、汇总函数


1、distinct:过滤出唯一列


select distinct filed1,field2 from 表

过滤出filed1,field2组成的唯一字段

2、分组函数

分组过滤


3、子查询:

查询结果作为表


4、表关联


inner join:



union,union all关键字

union:将两个表查询出来的的数据合并为同一个表(去掉重复)

union all:不去重复


表复制

create table if not exists aa
as select * from  city;
删除表
drop table if exists aa

表定义:

基本的数据类型


create table test(
id int,
name varchar(30),
age int,
language varchar(50),
primary key(id)
)

添加列:

alter table test add new_name varchar(100)

删除列:

alter table 表名 drop 列名

修改字段类型:

alter table test MODIFY name varchar(300)

修改字段名称:

alter table test  change name nname varchar(300)

四、null值说明


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值