1、先创建一个学生表

create table students (

id int auto_increment not null primary key,

name varchar(20)  not null,

age int unsigned default null,

height decimal(5,2) default null,

gender enum('男','女','保密') default '保密',

cls_id int unsigned default 0

);

在创建一个班级表

create table classes (

id int unsigned not null primary key,

name varchar(20) not null

);

2、逻辑运算符

(1)查询编号大于3的女同学:select * from students where id > 3 and gender=0;

(2)查询编号小于4或年龄大于20的学生:select * from students where id < 4 or age>20;

3、模糊查询

(1)查询姓黄的学生:select  *  from students where name like '黄%';

   (2)查询姓黄并且“名”是一个字的学生:select  *  from students where name like '黄_';

   (3)查询姓黄或叫靖的学生:select  * from students where name like '黄%' or name like '%靖';

4、范围查询

  (1)查询编号是1或3或8的学生(非连续范围):select * from students where id in(1,3,8);

  (2)查询编号为3至8的学生(连续范围查询):select * from students where id between 3 and 8;

5、空判断

  (1)查询没有填写身高的学生:select * from students where height is null;

  (2)查询填写了身高的学生:select * from students where height is  not null;

  (3)查询填写了身高的男生:select * from students where height is not null and gender='男';

6、排序

    注解:将行数据按照列1进行排序,如果某些行列1的值相同时,则按照列2排序,以此类推默认按照列值从小到大排列(asc)asc从小到大排列,即升序desc从大到小排序,即降序

  (1)显示所有的学生信息,先按照年龄从大-->小排序,当年龄相同时 按照身高从高-->矮排序:select * from students order by age desc,height desc;

7、聚合函数

  (1)查询学生总数:select  count(*)  from students;

  (2)查询女生的编号最大值: select max(id)  from students where gender='女';

  (3)查询男生的编号最小值: select min(id)  from students where gender='男';

  (4)查询男生的总年龄: select sum(age) from students where gender='男;

  (4)查询未年龄大于20的女生的编号平均值: select avg(id)  from students where age>20 and gender='女';
8、分组

  (1)查询性别为男的平均年龄,总人数,以及包含哪些人:select gender,count(*),avg(age),group_concat(name) from studetns group by gender having gender=1;

9、连接查询

内连接查询(取俩个表的交集,没有则不显示)

  (1)查询每个学生对应的班级:select * from studetns as s inner join classes c on s.cls_id=c.id;

   左连接查询(已左表为基准)

  (2)查询每个学生对应的班级:select * from studetns as s left join classes c on s.cls_id=c.id;

  右连接查询

  (3)查询每个学生对应的班级: select * form studetns as s right join classes on s.cls_id=c.id;

10、分页查询

  (1)查询第二页,每页显示2个:select * from studetns limit 2,2;

网络编程-Mysql-2、各种查询的更多相关文章

  1. linux学习笔记4:linux的任务调度,进程管理,mysql的安装和使用,ssh工具的使用,linux网络编程

    1.设置任务调度命令crontab 任务调度是指系统在某个时间执行的特定的命令或程序.任务调度分为:1)系统工作:有些重要的工作必须周而复始的执行,如病毒扫描.2)个别用户工作:个别用户可能希望执行某 ...

  2. Android之网络编程利用PHP操作MySql插入数据(四)

    因为最近在更新我的项目,就想着把自己在项目中用到的一些的简单的与网络交互的方法总结一下,所以最近Android网络编程方面的博文会比较多一些,我尽量以最简单的方法给大家分享,让大家明白易懂.如果有什么 ...

  3. 网络编程-Java中的Internet查询

    前提 在深入理解URL.URI等概念,或者学些Socket相关的知识之,有必要系统理解一下Internet相关的一些基础知识. Internet地址 连接到Internet(因特网)的设备称为节点(n ...

  4. 第四模块:网络编程进阶&数据库开发 第2章·MySQL数据库开发

    01-MySQL开篇 02-MySQL简单介绍 03-不同平台下安装MySQL 04-Windows平台MySQL密码设置与破解 05-Linux平台MySQL密码设置与破解 06-Mac平台MySQ ...

  5. iOS UI高级之网络编程(HTTP协议)

    HTTP协议的概念 HTTP协议,Hyper Text Transfer Protocol (超文本传输协议)是用于从万维网服务器传送超文本到本地浏览器的传输协议,HTTP是一个应用层协议,由请求和响 ...

  6. 第十三章:Python の 网络编程进阶(二)

    本課主題 SQLAlchemy - Core SQLAlchemy - ORM Paramiko 介紹和操作 上下文操作应用 初探堡垒机 SQLAlchemy - Core 连接 URL 通过 cre ...

  7. day8网络编程,面向对象1

    一.只是回顾 1.导入模块的顺序,首先从当前目录下找,再从环境变量里面找,使用"sys.path.insert(0,'需要导入的环境变量')"加入需要导入文件的环境变量; 2.如果 ...

  8. Socket网络编程--聊天程序(7)

    接上一小节,本来是计划这一节用来讲数据库的增删改查,但是在实现的过程中,出现了一点小问题,也不是技术的问题,就是在字符界面上比较不好操作.比如要注册一个帐号,就需要弄个字符界面提示,然后输入数字表示选 ...

  9. Socket网络编程--聊天程序(8)

    上一节已经完成了对用户的身份验证了,既然有了验证,那么接下来就能对不同的客户端进行区分了,所以这一节讲实现私聊功能.就是通过服务器对客户端的数据进行转发到特定的用户上, 实现私聊功能的聊天程序 实现的 ...

随机推荐

  1. Flask 视图,中间件

    视图 FBV def index(nid): """ 请求相关信息 request.method # 请求方式 request.args # get 方式的参数获取 re ...

  2. 【WC2018】即时战略

    题目描述 小M在玩一个即时战略(Real Time Strategy)游戏.不同于大多数同类游戏,这个游戏的地图是树形的. 也就是说,地图可以用一个由 n个结点,n?1条边构成的连通图来表示.这些结点 ...

  3. beam 的异常处理 Error Handling Elements in Apache Beam Pipelines

    Error Handling Elements in Apache Beam Pipelines Vallery LanceyFollow Mar 15 I have noticed a defici ...

  4. Springboot 6.Springboot 返回cookies信息的验证和post接口开发及常见错误解决

    在介绍之前先将一个小插件:lombok  ,在prefrence里面点击plugins,然后搜索lombok,进行install就可以了 首先将pom文件里面的lombok引进来 <depend ...

  5. jq常用操作

    1. 将滚动条置于底部 var srcH = $(".msg-IOC").prop("scrollHeight");$('.msg-IOC').scrollTo ...

  6. mtd-utils 安装

    title: mkdosfs 安装 tags: linux date: 2018/12/26/ 17:08:54 --- mtd-utils安装 for 主机 在制作根文件系统中需要使用它制作jffs ...

  7. openstack项目【day23】:keystone组件网关协议

    本节内容 一 静态页面和动态页面 二 什么是web server 三 什么是网关协议 3.1 引子 3.2 网关协议 四 网关协议CGI.FastCGI.WSGI.UWSGI 五 网关协议与keyst ...

  8. Docker:常用命令大全 [七]

    一.docker的命令的解释 1.命令解释 docker run -d -p 80:80 nginx run (创建并运行一个容器) -d 放在后台 -p 端口映射 nginx docker镜像的名字 ...

  9. Java String相关

    一.String类的常用方法 1. int indexOf(String s) 字符串查找 2. int lastIndexOf(String str) 3. char charAt(int inde ...

  10. [数学笔记Mathematical Notes]1-调和级数发散的一个简单证明

    定理. 调和级数 $\dps{\vsm{n}\frac{1}{n}}$ 是发散的. 证明. 设 $$\bex a_n=\sum_{k=1}^n\frac{1}{k}, \eex$$ 则 $a_n$ 递 ...