使用的sql图形软件:SQLyogEntsql
使用的数据库:MYSQL5.7数据库
软件地址:函数
连接:https://pan.baidu.com/s/1lajyXaSnmrO1v5v987NOoA
提取码:i3a4
spa
-------------------------------------------------------------------------------------------------------------------------------------排序
//建立名为student的数据库get
create database student;产品
//显示数据库是否建立成功io
show databases;table
//跳转到本身想要作修改的表,指定操做的数据库名为student效率
use student;
//建立stu表,在建立时指定属性和属性类型,并给于这个属性指定大小
create table stu(id int(4),name varchar(12),age int(10),sex char(2),birthday date);
//显示是否建立表成功
show tables;
//显示数据库stu表的基础信息
desc stu;
//插入数据,varchar和char还有date类型数据使用‘’括起来
insert into stu values(1,'we',11,'n','2019-11-12');
//插入数据有两种方式,一种是指定属性插入和所有属性插入
insert into stu(id,name) values(1,'ju');
insert into stu values(2,'w',11,'n','2019-11-12'),(3,'w',11,'n','2019-11-12'),(4,'w',11,'n','2019-11-12');//连着插入三条数据
//删除student数据库
drop database student;
//删除stu表
drop table stu;
//修改数据库表的信息
update stu set name='jing' where age=11;
update stu set name='wan',age=18 where id=1;
//删除
delete from stu where id=1;
delete from stu where name='li' and age=18;
//查询
select * from product;//查询全部
select name,price from product;
select name,price+10 from product;//查询全部价格加十后的显示结果
select p.name,p.price from product AS p;//给表起别名,多用于多表查询
select name,price+10 AS "产品的新价格" from product;//给列起别名
select * from product where name="华为电脑001";//查询条件为name="华为电脑001"的所有记录
select *from product where price!=23;//价格不等于23的全部记录
select *from product where price>23 and price<100;//查找价格23到100之间的记录
select * from product where price between 23 and 100;//查找价格23到100之间的记录,包含23
select * from product where price = 23 or price=100;//价格等于23或100的全部记录
select * from product where price in(23,100);//等同于上一句
//碰到关键字在输入的名称左边加顿号
select distinct type from product;//查找全部type并使用distinct去除重复
select * from product where type is null;//查询出没有分类的全部记录
select * from product where type is not null;//查询出有分类的全部记录
select * from product order by price asc;//按照价格的大小升序排序
select * from product order by price desc;//按照价格的大小降序排序
//聚合函数
select count(*) AS "总数" from product;//统计有多少条记录,并起个别名(效率低不建议使用)
select count(1) as "总数" from product;//建议这样使用 1 表明只遍历统计下标为1的属性
select sum(price) from product;//查询出全部的价格总和
select max(price) from product;//查询价格最高
select min(price) from product;//查询最低价格
select avg(price) from product;//查询价格的平均值
select avg(price) as '平均值',min(price) as '最小值',max(price) as '最大值' from product;
select avg(price) as '平均值',min(price) as '最小值',max(price) as '最大值' ,count(1) as '总记录数'from product;
模糊查询
select *from product where name like '%电%';//%表明匹配一个或者多个字符,_ 只匹配一个字符
分组操做
select * from product group by type;//根据type进行分组,分组后重复会被去掉
分组后进行过滤,筛选
select * from product group by type having type is not null;