java1

Mysql基本语法

基础命令

show databases;  //查看数据库列表
create databases shop;  //创建一个名为shop的数据库
use shop;//使用shop库

//建一张名为Proudct的表
//包含一个id字段 字段类型为int(整数)not null表示不允许为null,promary key表示该字段为主键,auto-increment表示自动增长
create table Proudct (id int not null primary key auto-increment);

//添加表结构语句,添加一个名为name的,类型为varchar(字符串,长度为100)的属性到proudct表中
alter table Proudct add column name varchar(100);

//删除表结构语句
alter table Proudct drop column name;

//查看proudct的表结构
desc Proudct;

//添加一条数据小括号里写我要添加哪些字段,values后按照顺序写值
insert into Product(name,price,type) values ('帽子',99,'服饰');

//查询Product表中全部的数据
select * from Proudct;

//删除Product表中id为1的数据
delete from Product where id=1;

//修改Product表中id为2的记录的name值为拖鞋
update Proudct set name='拖鞋' where id=2;

//条件查询
mysql> select * from Proudct where type='服饰';

//多个条件查询
select * from Proudct where type='服饰'and price>=100;


//查整个库里的商品名和价格
select name,price from Proudct;

//打八折
select name,price,price * 0.8 As price2 from Proudct;

//
select name As proudct_name,price,price * 0.8 As price2 from Proudct;


//价格高于300的打八折
select name,price,price * 0.8 As price2 from Proudct where price >300;


//价格小于300 的打九折
select name,price,price * 0.9 As price2 from Proudct where price <=300;


//最高价格
select max(price) from Proudct;

//最大最小值
select max(price),min(price) from Proudct;

//平均价格
select avg(price) from Proudct;

//新建
insert into Proudct (name,price,type) values ('外套F',99,'衣服');

//
rollback

//
commit;

//衣服小于等于300打九折
select name,price,price * 0.9 As price2 from Proudct where price <=300 and type='衣服';

//查总数
select distinct type from Proudct;

//
select type,count(*) from Proudct group by type;
# Mysql基本语法

### 基础命令
```java
show databases;  //查看数据库列表
create databases shop;  //创建一个名为shop的数据库
use shop;//使用shop库

//建一张名为Proudct的表
//包含一个id字段 字段类型为int(整数)not null表示不允许为null,promary key表示该字段为主键,auto-increment表示自动增长
create table Proudct (id int not null primary key auto-increment);

//添加表结构语句,添加一个名为name的,类型为varchar(字符串,长度为100)的属性到proudct表中
alter table Proudct add column name varchar(100);

//删除表结构语句
alter table Proudct drop column name;

//查看proudct的表结构
desc Proudct;

//添加一条数据小括号里写我要添加哪些字段,values后按照顺序写值
insert into Product(name,price,type) values ('帽子',99,'服饰');

//查询Product表中全部的数据
select * from Proudct;

//删除Product表中id为1的数据
delete from Product where id=1;

//修改Product表中id为2的记录的name值为拖鞋
update Proudct set name='拖鞋' where id=2;

//条件查询
mysql> select * from Proudct where type='服饰';

//多个条件查询
select * from Proudct where type='服饰'and price>=100;


//查整个库里的商品名和价格
select name,price from Proudct;

//打八折
select name,price,price * 0.8 As price2 from Proudct;

//
select name As proudct_name,price,price * 0.8 As price2 from Proudct;


//价格高于300的打八折
select name,price,price * 0.8 As price2 from Proudct where price >300;


//价格小于300 的打九折
select name,price,price * 0.9 As price2 from Proudct where price <=300;


//最高价格
select max(price) from Proudct;

//最大最小值
select max(price),min(price) from Proudct;

//平均价格
select avg(price) from Proudct;

//新建
insert into Proudct (name,price,type) values ('外套F',99,'衣服');

//
rollback

//
commit;

//衣服小于等于300打九折
select name,price,price * 0.9 As price2 from Proudct where price <=300 and type='衣服';

//查总数
select distinct type from Proudct;

//
select type,count(*) from Proudct group by type;


price int      //商品价格
type varchar(20)   //商品类型
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 对于一年经验的Java开发人员,以下是一些常见的技术和能力要求: 核心Java技术:熟悉Java语言的基础知识,包...
    大连赵哥阅读 118评论 0 1
  • 目录1简介41.1背景41.2适用对象41.3假设和约束42Java学习路线52.1基础知识52.1.1Java语...
    柳仁儿阅读 315评论 0 0
  • 注释 1、单选注释:符号是:// 2、块注释: 符号是: /* */ 可以跨多行 3、javadoc注释: 符号...
    蔡大爷的小甜心阅读 409评论 0 1
  • 字符,字符集,字符编码,内容详尽的文章ASCII 一个字节一个字符ANSI (GBK)两个字节表示一个字符U...
    愉快先生阅读 138评论 0 0
  • 2.Java环境配置 系统变量JAVA_HOME = D:\jclisoft\jdk1.8.0_202编辑变量pa...
    LI耳阅读 865评论 4 61