mysql数据库 学习(实训练习)

1、在数据库中新建一张 product表:包括字段p_id(int)、p_Name(varchar)、price(double)、num(int)、company(varchar)、address(varchar)

create table product
(
	p_id int not null primary key auto_increment,
    p_Name varchar(4),
    price double(6,2),
    num int,
    company varchar(10),
    address varchar(10)
);

2、新增几条产品记录:电视机、冰箱、服装、手机;(按照下面的数据插入)

insert into product
(`p_Name`,`price`,`num`,`company`,`address`)
values
("电视",1000.00,800,"长虹","成都"),
("电视",1000.00,1000,"海尔","成都"),
("冰箱",1800.00,300,"长虹","北京"),
("冰箱",3500.00,500,"海尔","重庆"),
("服装",280.00,1000,"雅戈尔","成都"),
("服装",1200.00,200,"雅戈尔","北京"),
("手机",2500.00,200,"华为","深圳"),
("手机",200.00,1200,"",""),
("手机",204.00,1500,"","");
("手机",202.00,1000,"","");

3、将所有电视机的数量修改为1000台,将所有手机的价格修改为2500元;

-- 修改所有num
update product set num = 1000;

update product set num = 1000 where p_Name = "电视" ;
update product set price = 2500 where p_Name = "手机" ;

4、删除手机价格介于1000元和2000元之间的记录;

delete from product where price between 1000.00 and 2500.00;

5、查询出所有价格大于200元的服装或价格小于5000元的冰箱;

select * from product where p_Name ="服装"  or p_Name = "冰箱" and (200 > price < 5000) ;

select * from product where p_Name='冰箱' and price<=5000 or p_Name="服装" and price>=200;

例如:
1 电视 1000.00 800 长虹 成都
2 电视 1000.00 1000 海尔 成都
3 冰箱 1800.00 300 长虹 北京
4 冰箱 3500.00 500 海尔 重庆
5 服装 280.00 1000 雅戈尔 成都
6 服装 1200.00 200 雅戈尔 北京
7 手机 2500.00 200 华为 深圳
8 手机 200.00 1200
9 手机 204.00 1500
10 手机 202.00 1000

1、新建一张表Student表,包括字段:

      s_id(学生id,整型,主键),
    
      s_number(学号,整型),
    
      s_name(姓名,字符型),
    
      s_age(年龄,整型),
    
      s_tel(电话,字符型),
    
      s_address(地址,字符型),
    
      s_score(成绩,浮点型),
    
       其中,s_id(学生ID)为主键;
create table Student
(
	s_id int not null primary key auto_increment,
    s_number int,
    s_name varchar(10),
    s_age int,
    s_tel varchar(11),
    s_address varchar(20),
    s_score double(6,2)
);

2、插入10条记录,显示不同的学生记录,以s_id进行区分;

insert into Student
(`s_number`,`s_name`,`s_age`,`s_tel`,`s_address`,`s_score`)
values
(19301041,"小一",18,"13419171453","四川成都",89),
(19301042,"小二",19,"13419171454","四川成都",80),
(19301043,"小三",20,"13419171455","四川成都",62),
(19301044,"小四",21,"13419171456","四川成都",77),
(19301045,"小五",22,"13419171457","四川成都",98),
(19301046,"小六",23,"13419171458","四川成都",38),
(19301047,"小七",17,"13419171459","四川成都",79);

3、查询出student表中分数大于80分或分数小于60分的学生;

select * from Student where s_score>80 or s_score<60;

4、查询出年龄在18岁以上的学生,并按照s_score的降序,s_number的升序进行排序;

select * from Student where s_age>18  order by s_score desc, s_number asc;

5、查询出年龄介于25岁至35岁之间的学生记录;

select * from Student where s_age  between 25 and 35;

6、将表中所有年龄大于18岁的学生的地址修改为"成都",电话修改为"135***";

update Student set s_address="成都",s_tel="135***" where  s_age > 18;
posted @ 2021-09-06 17:29  阿向向  阅读(519)  评论(0编辑  收藏  举报