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. 学习Spring Boot:(十五)使用Lombok来优雅的编码

    前言 Lombok 是一种 Java™ 实用工具,可用来帮助开发人员消除 Java 的冗长,尤其是对于简单的 Java 对象(POJO).它通过注解实现这一目的. 正文 添加依赖 在 pom.xml ...

  2. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  3. BZOJ3932 主席树

    https://www.lydsy.com/JudgeOnline/problem.php?id=3932 题意:给出一些带有等级的线段,求一点上前K小个等级线段的等级之和 询问是对于每一个点询问前K ...

  4. 分布式监控系统开发【day38】:报警策略队列处理(五)

    一.目录结构 二.报警策略队列处理 1.入口MonitorServer import os import sys if __name__ == "__main__": os.env ...

  5. 金融量化分析【day111】:Matplotib-图标标注

    一.图像标注 1.股票 df = pd.read_csv('601318.csv') df.plot() plt.plot([1,3,4,5]) plt.plot([5,8,7,9]) plt.tit ...

  6. 使用Spring-Integration实现http消息转发

    目标:接收来自华为云的服务器报警信息,并转发到钉钉的自定义机器人中 使用Spring-Integration不仅节省了很多配置,还增加了可用性. 更多关于Spring-Integration的介绍可参 ...

  7. [Everyday Mathematics]20150306

    在王高雄等<常微分方程(第三版)>习题 2.5 第 1 题第 (32) 小题: $$\bex \frac{\rd y}{\rd x}+\frac{1+xy^3}{1+x^3y}=0. \e ...

  8. 分享一个jsonp劫持造成的新浪某社区CSRF蠕虫

    最近jsonp很火,实话说已经是被玩烂了的,只是一直没有受到大家的重视.正好在上个月,我挖过一个由于jsonp造成的新浪某社区CSRF,当时是为了准备一篇文章,之后这篇文章也会拿出来分享. 因为新浪已 ...

  9. Nginx 站点设置目录列表显示

    Nginx 站点目录列表显示. 可以编辑添加在 server { } 模块 或者 location { } 模块下. autoindex on; # 开启目录文件列表 autoindex_exact_ ...

  10. 转载-CentOS7关闭防火墙

    原文地址-http://www.cnblogs.com/silent2012/archive/2015/07/28/4682770.html CentOS 7.0默认使用的是firewall作为防火墙 ...