MySQL(2)

七、DML操作表中的数据

1.添加数据

  • 语法:INSERT INTO 表名 (字段名 1, 字段名 2, 字段名 3…) VALUES (值 1, 值 2, 值 3);
  • 注意:
    1.列名要和值一一对应
    2.如果表明后不写列名,就默认给所有列添加值
    3.除了数据类型都要用引号引起来
    2.删除数据
  • 语法:delect from 表名 (where 条件)
  • 注意:
    1.如果不加条件,则删除表中所有数据
    2.如果删除所有数据
    truncate table 表名;
    3.修改数据
  • 语法:update 表名 set 列名1=值1, 列名2=值2,…(where 条件);
  • 注意:
    1.如果不加任何条件,则会将表中所有记录全部修改

九、简单查询

  1. 查询行和列
select * from student; #查询所有的学生
select name,age from student; #但显示名字和年龄
select distinct address from student; #去除重复的结果集
select name,math,english,math+ifnull(english,0)from student; #显示英语和数学成绩总和
select name,math,english,math+ifnull(english,0) 总分 from student; #起别名
  1. 条件查询
select * from student where age>=20; #查询年龄大于等于20的学生
select * from student where age=20;  #查询年龄等于20的学生
#!=   <> 不等于
select * from student where age<=30 and age>=20; #查找20到30岁的学生
select * from student where age between 20 and 30;
select * from student where age in (20,18,25); #查找年龄为20,18,25的学生
# null 不能使用符号判断
select * from student where english is null;
select * from student where english is not null;
/*like _:单个任意字符
      %:多个任意字符*/
select * from student where name like '马%';  #姓马的人
select * from student where name like '_化%';  #第二个字是化的人
select * from student where name like '___';  #三个名字的人
select * from student where name like '%马%'; #带有马字的人

`

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值