mysql中update去重_MySQL 命令操作

Mysql进入与退出

进入数据库:mysql -uroot -p

退出: exit

库级操作语句

显示所有的表:show databases;

创建库: create database 库名; (重复创建会报错,可在库名前加上[if not exists])

删除库: drop database 库名;(如果不知道数据库是否存在,记得在库名前加[if exists])

进入数据库:use 库名;

表级操作语句

显示所有的表: show tables;

创建表: create table 表名;(重复创建会报错,可在表名前加上[if not exists])

显示创建表的信息: show create table 表名;

删除表:drop table 表名;

MysSQL表中数据的操作

插入数据(create) insert into values

指定字段插入: insert into 表名(表头)value(插入信息);

全字段插入:  insert into 表名value (插入整段信息);

多行插入: insert into 表名 value(插入信息),(插入信息),…;

查询数据 (read) select from where

指定字段查询: select 表头 from 表名;

2.全字段查询:select * from 表名;(select查询关键字,  * 代表所有 )

带条件查询:select 表头1 from 表名 where 表头2  条件;

例:select name from student where age = 19;

(查询学生表里年龄等于19的姓名)

select * from 表名 where 表头字段 条件;

例:select * from student where age = 19;

(查询学生表里等于19岁的全部字段)

修改数据(update)update set where

修改所有数据:update 表名 set 表头字段 = 条件;

修改多个数据:update 表名 set 表头字段 = 条件, 表头字段2 = 条件2;

修改满足条件的数据:update 表名 set 表头字段1 = 条件1  where 表头字段2 = 条件2;

例:update student set id = 5 where name =某某;

(把学生表姓名为某某的id改成5)

删除数据 (delete)delete from where

删除表中所有数据: delete from 表头字段;

删除表中满足条件的数据:delete from 表头字段 where 表头字段 = 条件;

例:delete from student where name = 某某;

(删除学生表里某某整行值)

MySQL数据类型:

数值类型、字符类型、时间日期类型

数值类型常用举例

20190403223140191468.png

字符类型常见举例

20190403223140365296.png

时间日期类型

20190403223140608460.png

案例

20190403223140725648.png

MySQL筛选条件

20190403223140929750.png

In null例子

select * from student where id is null;

错误例子: select * from student where is = null;(这样是显示不了的,空值以这种方式查询是查不出来的)

in not null例子

select * from student where id is not null;

与或非

and or not

and 例子:select * from student where id =5 andage = 9;

or  例子:select * from student where id =5 orage = 9;

20190403223141044984.png

排序(order by)

正序举例:select * from student order by age;

倒序举例:select * from student order by age desc;

限制(limit)

举例:select * from student limit 0,5;

(MySQL是 左闭右闭)

20190403223141248109.png

去重(distinct)

举例:select distinct * from student;

20190403223141413148.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值