创建表:

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的记录

mysq基础操作的更多相关文章

  1. python基础操作以及hdfs操作

    目录 前言 基础操作 hdfs操作 总结 一.前言        作为一个全栈工程师,必须要熟练掌握各种语言...HelloWorld.最近就被"逼着"走向了python开发之路, ...

  2. MYSQL基础操作

    MYSQL基础操作 [TOC] 1.基本定义 1.1.关系型数据库系统 关系型数据库系统是建立在关系模型上的数据库系统 什么是关系模型呢? 1.数据结构可以规定,同类数据结构一致,就是一个二维的表格 ...

  3. 【Learning Python】【第二章】Python基础类型和基础操作

    基础类型: 整型: py 3.0解决了整数溢出的问题,意味着整型不必考虑32位,64位,有无符号等问题,你写一个1亿亿亿,就是1亿亿亿,不会溢出 a = 10 ** 240 print(a) 执行以上 ...

  4. Emacs学习心得之 基础操作

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Emacs学习心得之 基础操作 1.前言与学习计划2.Emacs基础操作 一. 前言与学习计 ...

  5. Git基础操作

    配置秘钥 1.检查本机有没有秘钥 检查~/.ssh看看是否有名为d_rsa.pub和id_dsa.pub的2个文件. $ ~/.sshbash: /c/Users/lenovo/.ssh: Is a ...

  6. activiti基础操作

    package activitiTest; import java.io.InputStream; import java.util.List; import java.util.zip.ZipInp ...

  7. 《Genesis-3D开源游戏引擎-官方录制系列视频教程:基础操作篇》

    注:本系列教程仅针对引擎编辑器:v1.2.2及以下版本 G3D基础操作   第一课<G3D编辑器初探> G3D编辑器介绍,依托于一个复杂场景,讲解了场景视图及其基本操作,属性面板和工具栏的 ...

  8. MYSQL 基础操作

    1.MySQL基础操作 一:MySQL基础操作 1:MySQL表复制 复制表结构 + 复制表数据 create table t3 like t1; --创建一个和t1一样的表,用like(表结构也一样 ...

  9. php之文件基础操作

    在php中对文件的基础操作非常的简单,php提供的函数粗略的用了一遍. file_get_contents():可以获取文件的内容获取一个网络资源的内容,这是php给我封装的一个比较快捷的读取文件的内 ...

随机推荐

  1. 阿里巴巴的26款超神Java开源项目!

    来源:https://segmentfault.com/a/1190000017346799 1.分布式应用服务开发的一站式解决方案 Spring Cloud Alibaba Spring Cloud ...

  2. webpack4.0各个击破(9)—— karma篇

    webpack作为前端最火的构建工具,是前端自动化工具链最重要的部分,使用门槛较高.本系列是笔者自己的学习记录,比较基础,希望通过问题 + 解决方式的模式,以前端构建中遇到的具体需求为出发点,学习we ...

  3. MEF 基础简介 一

    前言 小编菜鸟级别的程序员最近感慨颇多,经历了三五春秋深知程序路途遥远而我沧海一粟看不到的尽头到不了的终点何处是我停留的驿站.说了段废话下面进入正题吧! 什么是MEF? MEF:全称Managed E ...

  4. _C#发送邮箱

    public ActionResult lead() { SendEmail("邮箱号", "吃饭么?", "你要吃什么啊"); retur ...

  5. IOC的理解,整合AOP,解耦对Service层和Dal层的依赖

    DIP依赖倒置原则:系统架构时,高层模块不应该依赖于低层模块,二者通过抽象来依赖依赖抽象,而不是细节 贯彻依赖倒置原则,左边能抽象,右边实例化的时候不能直接用抽象,所以需要借助一个第三方 高层本来是依 ...

  6. Spring Boot使用AOP在控制台打印请求、响应信息

    AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等. AOP简介 AOP全称Aspect Oriented Programming,面向切面,AOP主要实现的 ...

  7. Linux CentOS设置定时重启:crontab

    上一篇介绍了 开机自启动chkconfig命令  https://www.cnblogs.com/prefectjava/p/9399470.html 本篇介绍 crontab 设置定时任务,并且把 ...

  8. React的组件模式

    组件是 React 的核心,因此了解如何利用它们对于创建优秀的设计结构至关重要. 什么是组件 根据 React 官网的介绍,"组件让你可以将 UI 分割成独立的.可重用的部分,并独立管理每个 ...

  9. Vue项目用了脚手架vue-cli3.0,会报错You are using the runtime-only build of Vue where the template compiler is not available.....

    摘自: https://blog.csdn.net/wxl1555/article/details/83187647 报错信息如下图: 报错原因是:vue有两种形式的代码:一种是compiler(模版 ...

  10. Android 解析标准的点击第三方文件管理器中的视频的intent

    解析标准的第三方视频intent private List<String> mCurPlayList = new ArrayList<String>(); private in ...