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. bzoj 1208: [HNOI2004]宠物收养所 (Treap)

    链接:  https://www.lydsy.com/JudgeOnline/problem.php?id=1208 题面: 1208: [HNOI2004]宠物收养所 Time Limit: 10 ...

  2. css流式布局

    elem{ width:1160px;/*流式布局的总宽度*/ column-width:375px; -moz-column-width: 375px; /*每列宽度*/ -webkit-colum ...

  3. JQGrid导出Excel文件

    系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...

  4. nginx的信号量

    一.官方文档 https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/ 二.nginx进程说明 一般在nginx ...

  5. centos7防火墙设置

    前言 CentOS7 与之前版本在防火墙配置上不同,防火墙从iptables变成了firewalld Centos7默认安装了firewalld,如果没有安装的话,可以使用yum命令进行安装 yum ...

  6. Python字节数组【bytes/bytearray】

    bytes >>> type(b'xxxxx') <class 'bytes'> >>> type('xxxxx') <class 'str'&g ...

  7. main 及Scanner

    通过main方法的args数组可以从控制台获取一组字符串数据. 1.Scanner类用于扫描从控制台输入的数据,可以接收字符串和基本数据类型的数据. 2.Scanner类位于java.util.Sca ...

  8. Spring系列(零) Spring Framework 文档中文翻译

    Spring 框架文档(核心篇1和2) Version 5.1.3.RELEASE 最新的, 更新的笔记, 支持的版本和其他主题,独立的发布版本等, 是在Github Wiki 项目维护的. 总览 历 ...

  9. eclipse工程的jdk从1.7升到1.8后报错解决办法

    报的错误信息: org.apache.jasper.JasperException: Unable to compile class for JSP 讲Tomcat从7.0升到apache-tomca ...

  10. webstorm允许移动端访问本地html页面的方法