# Mysql基本语法
### 基本命令
```java
show databases;//查看数据库列表
create database shop;//创建一个名为shop的数据库
use shop;//使用数据库shop
//创建一张名为Product的表
//包含一个id字段 字段类型为int(整数)not null 表示不允许为null, promary key 表示该字段为主键,auto_increment表示自动增长
create table Product( id int not null primary key auto_increment);
alter table Product add column name varchar(100);//增加表结构添加一个名为name的类型为varchar(字符串 长度为100)的属性到Paoduct表中
alter table Product drop column name;//删除表结构
desc Product;//查看表结构
//添加一条数据小括号里写我要添加哪些字段,values后按照顺序写值
insert into Product(name,price,type)values("帽子",99,"服饰");
//查询Product表中全部的数据
select * from Product;
//删除Product表中id为1的数据
delete from Product where id = 1;
//添加数据
insert into Product(name,price,type)values("帽子",20,"服饰");
insert into Product(name,price,type)values("裤子",120,"服饰");
insert into Product(name,price,type)values("卫衣",160,"服饰");
insert into Product(name,price,type)values("牙刷",99,"生活用品");
//查找type为服饰的数据
select * from Product where type = "服饰";
//查找type为服饰并且价格大于100的数据;
select * from Product where type = "服饰" and price >=100;
DESC product;
insert into Product values(1,"外套A",300,"衣服");
DESC product;
select * FROM product;
insert into Product values(6,"外套B",350,"衣服");
select * FROM product;
insert into Product values(7,"鞋子A",200,"鞋");
select * FROM product;
SELECT * from product WHERE type = '衣服';
SELECT name, price from product;
SELECT type FROM product;
//查询内容
SELECT type FROM product GROUP BY type;
//分组查询
SELECT DISTINCT type from product;
//去重查询
SELECT type, COUNT(*) from product GROUP BY type;
//分别统计每组有多少种
select name AS product_name,price, price*0.8 AS price2 from product;
// AS 改名
//查找type是衣服的并且打九折后价格小于300的
SELECT name,price,price*0.8 AS price2 from product WHERE price>300;
SELECT name,price,price*0.9 AS price2 from product WHERE price <= 300;
SELECT name,price,price*0.9 AS price2 from product WHERE price <= 300 AND type='衣服';
select SUM(price) from product;
//总和
select AVG(price) FROM product;
//平均值
SELECT MAX(price) FROM product;
//最大值
SELECT MAX(price),MIN(price) FROM product;
//最大值和最小值
```