今日上午学习mysql-添加 修改 查询 排序(order key)

发布时间:2023年12月22日

添加数据

insert into 表名 values(),(),();这是写在一起的

insert into 表名(值1,值2,值3) values();这是单个在一起的

正规一般使用的是insert into 表名(值1,值2,值3) values();

下面是代码

#第一题
create database day03;
use day03;
drop table student;
create table student (
  id   int primary key auto_increment,
  name varchar(200),
  sex  varchar(1),
  age  int(19),
  oid  int(1),
  data date
);
insert into student
values (null, "苏鑫烁", "男", 19, 1, "20041225"),
       (null, "吴晨阳", "男", 11, 2, "20051225"),
       (null, "陈毓乾", "男", 21, 1, "20061225");
#查看
select *
from student;


#查看录入
insert into student (id, name, sex, age, oid, data)
values (null, "烁烁", "女",19, 2, "20061111");
#查询姓名、性别、年龄排序
select name,sex ,age from student
where oid=2 order by age;

select *from student
where name like '苏%'and sex='男';

select *from student
where id=1 or id=3 or id=5 and sex ="男";


#查询成年的成绩
select *from student
where age>=18;

#第二题
create database school1;
use school1;
create table product(
  id int(1) primary key auto_increment,
  name varchar(100) ,
  Price float(10,2),
  sort varchar(200),
  inventory varchar(100),
  expiration_time datetime
);
drop table product;
insert into product values
                           (null ,"牛奶",100.00,"奶类","200件","2023-10-01 10:10:10"),
                           (null ,"苹果",300.00,"果类","600件","2023-12-12 10:10:10"),
                           (null ,"香蕉",500.00,"果类","500件","2023-12-12 10:10:10");
insert into product values
                           (null ,"牛奶2",100.00,"奶类","300件","2023-10-01 10:10:10"),
                           (null ,"牛奶3",100.00,"奶类","600件","2023-10-01 10:10:10");
#查询100到500之间的几个然后排序

select * from product
where Price  between 100 and 500 order by inventory;
  查询出所有的名称带牛的商品,按照价格排序,价格一致,按照库存排序
select * from product
where name like '%牛%' order by Price,inventory ;
#查询出库存不足低于500个的商品信息
select *from product
where inventory>=500;

文章来源:https://blog.csdn.net/sxs04/article/details/135126559
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。