前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql初学

mysql初学

作者头像
机器学习和大数据挖掘
发布2019-07-02 10:40:47
3300
发布2019-07-02 10:40:47
举报
文章被收录于专栏:数据挖掘数据挖掘

本文基于mysql5.1编写

1、创建表:

代码语言:javascript
复制
1 create table customer(mid char(5) primary key, name varchar(20),age int(2) default'0');

2、删除表:

1 drop table customer;

3、部分列插入元素:

1 insert into customer(mid,name) values('ID','姓名');

4、全部列插入元素可以简写:

代码语言:javascript
复制
1 insert into customer values('ID','姓名','年龄');

5、更新元素,将ID这个用户的姓名和年龄改成姓名1和年龄1:

代码语言:javascript
复制
1 update customer set name='姓名1',age='年龄1' where mid='ID';

6、删除元素,删除id这一行:

1 delete from customer where mid='ID';

7、普通查找:

1 select * from customer;

8、条件查找,找到年龄大于10但是不等于20的人的ID和姓名:

1 select mid,name from customer where age>=10 and age<>20;

9、模糊查找:

9.1、找到姓李的人的姓名

1 selsct name from customer where name like'李%';

9.2、找到对应ID的人的姓名

代码语言:javascript
复制
1 select name from customer where mid in ('ID1','ID2','ID3');

9.3、排序查找,按照年龄升序,然后降序找到ID和姓名

1 select mid,name from customer order by age asc,age desc;

10、内连接两表查询:

1 select name,age from customer inner join customerg on customer.mid=customerg.mid

上述式子等于利用表customer的mid和表customerg的mid进行匹配

匹配相当于将两个表共有的属性合并了一起

那么就可以在合并的表格里查找姓名和年龄

11、多个表连接

代码语言:javascript
复制
1 select customer.mid,customerg.age,customers.address
2 from
3 (customer inner join customerg on customer.mid=customerg.mid)
4 inner join customers on customer.mid=customers;

共有三个表

customer:ID和姓名

customerg:ID和age

customers:ID和地址

12、增加列:

1 alter table customers add address char(20);

13、修改数据类型

1 alter table customer modify address char(30);

14、修改列名称和数据类型:

1 alter table change adress address char(20);

15、删除列:

1 alter after customer drop address;

16、多表查询模板

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-08-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档