创建表:

create table customer(mid char(5) primary key,name varchar(20),birth date,sex char(1) DEFAULT '0');

显示表的结构;

desc customer;

插入:

insert customer values('N001','小小','1980-12-12',1);

检索;

select* from customer;

创建表的时候指定字符集:

create table customer(mid char(5) primary key,name varchar(20),birth date,sex char(1) DEFAULT '0')

charset=utf8;

显示所有的表;

show tables;

显示表的结构 desc customer;

删除表:drop table customer;

自增序列 auto_increment

create table goods(id int auto_increment primary key,name varchar(30));
insert into goods(name) value('桃子');

insert into customer(mid,name,sex)values('H0001','李佳',0);
insert into customer(mid,name,birth) values('G0001','杜依依','1974-09-18');
insert into customer(mid,name,sex)values('G0001','李玉',0);

更新存在的记录:

update customer set name='李玉枝',birth='1997-12-24' where mid='N001';

update customer set sex='0';

删除表中的记录;

delete from customer where mid='N002';

清除所有的数据;

truncate table customer;

数据检索select;

1.推荐明确指定列名

select mid,name from customer;

2.条件检索

select name,birth from customer where birth>='1980/01/01';

3.模糊检索

select name,birth from customer where name like '李%';

select name,birth from customer where name like '李_';

4.null条件

select name,birth from customer where birth  is NUll;

5.多个组合表达

select name,birth from customer where sex='0' and birth is not null;

select name,birth from customer where sex='0' or birth<'2000/3/3';

运算符优先级:not <and<or

6.结果排序; asc升序 desc 降序

select name,birth from customer order by sex asc,birth desc;

7.去得指定件数的记录 (eg:第5名到第九名的数据)

select name,birth from customer order by birth desc limit 2;

原则上limit语句要和order by语句同时使用,没同时使用则取出随机结果

8.数据分组

以特定字对记录进行整理称为分组化,group by 通常与统计函数进行使用

avg 平均数

count 件数

max 最大值

min 最小值

sum 合计值

统计男生女生多少人:

select sex ,count(mid) from customer group by sex;

9.列的别名

select sex ,count(mid) as cnt from customer group by sex;

count 统计的是非null的记录

最新文章

  1. vs15 preview5 离线安装包
  2. Linux 学习
  3. JSP教程推荐
  4. Yeoman自动构建js项目
  5. Base64的编码转换方式
  6. 在cmd下输入/g无效
  7. Model First:创建实体数据模型(ADO.NET 实体数据模型)
  8. URL方式访问Hadoop的内容
  9. .NET DataTable转化为json格式
  10. mvc form
  11. 【Python】排列组合itertools &amp; 集合set
  12. threejs 初识
  13. Python类与对象的理解
  14. Lucene全文检索入门使用
  15. nodejs学习笔记&lt;二&gt; 使用node创建基础服务器
  16. Android之微信支付
  17. ios 解决Wkwebview闪烁问题
  18. Class &#39;App\Http\Controllers\DB&#39; not found and I also cannot use a new Model
  19. MyCat的分片规则
  20. php多进程实现 亲测

热门文章

  1. springboot(五)过滤器和拦截器
  2. Redux,基础
  3. C#_Lamada帮助类
  4. C# 合并Excel工作表
  5. 51nod“省选”模测第二场 B 异或约数和(数论分块)
  6. AS使用自带虚拟机报错解决
  7. Android EditText常用属性
  8. Kotlin入门(33)运用扩展属性
  9. gitbook 入门教程之插件介绍
  10. CentOS7安装MySQL并配置账户等