数据库操作(单表)

1.-- 使用sql语句查询出表中的所有内容
select * from student;

 -- 使用sql语句查询出表中所有score>70的同学的id,name,score
select id,name,score from student where score>70;

 -- 更改name字段的数据类型为varchar(50)
alter table student modify name varchar(50);

 改之前

 改之后

 -- 向表中添加一个字段,字段名称为“pingjia”,字段类型为varchar(20)
alter table student add pingjia varchar(20);

改之前

 改之后

 -- 更改姓名是张三的同学的分数为88
update student set score=88 where name='张三';

改之前 

 改之后

-- 如果80分为及格线,查询出所有及格的同学的详细信息
select * from student where score>80;

 -- 使用关键字in,查询id值是1或5或7的同学的基本信息
select * from student where id in(1,5,7);

 -- 查询id值在5至8的所有同学的基本信息
select * from student where id between 5 and 8;

 -- 查询姓名是小红并且分数大于60的同学的基本信息
select * from student where name='小红' and score>60;

 -- 查询姓名是小红或者分数大于90的同学的基本信息
select * from student where name='小红' and score>90;

 没有符合要求的数据,查询不到

2.-- 向表中添加记录,字段对应值分别为(209,毛不易,男,604,4000,黑龙江齐齐哈尔)
        insert into teacher values(209,'毛不易','男',604,'4000','黑龙江齐齐哈尔');

 

 -- 查询表中所有记录
select * from teacher;

 -- 删除表中Number是201并且sex是女的教师信息
delete from teacher where number=201 and sex='女';

 

-- 查询表中Number字段的值是202,205或207教师的所有记录
select * from teacher where number in(202,205,207);

 -- 修改表中Number值是202教师的姓名为“马云”
update teacher set name='马云' where number=202;

 

-- 查询工资最高的前三条信息
select * from teacher order by salary desc limit 0,3;

 -- 查询姓名中包含张的信息
select * from teacher where name like'%张%';

 

 -- 查询男女生的个数信息
select count(*) as 个数,sex as 性别 from teacher group by sex;

 

 -- 查询薪资在1800到3600之间的信息

(方法一)
select * from teacher where salary>1800 and salary<3600;

 (方法二)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值