单表查询:

  select * from

select sname from stu;

条件查询

select sname from stu where sid=2;

select sname from stu where sid>2;

select sname from stu where sid!=2;

查询时取别名,

select sid as 学号,sname as 姓名 from stu;

模糊查询,

select * from stu where sname like '小%';    %  有多少相似查出多少,

select * from stu where sname like '小_';      _  有几条线,查出几条,,

select * from stu where sname like '小___';      _  有几条线,查出几条,,

排序    order by  字段名

select * from stu order by tzid 【asc】;    升

select * from stu order by tzid desc;        降

限制查询  limit

select * from stu limit 3;         可以理解为第 0 条开始往下 3条,

select * from stu limit 3,1    从第 3 条往下第 1 第,

平均值:

select avg(age) from dstu;      求培元年龄,

sql> select round(avg(age)) from dstu;        四舍五入平均值,统计

统计: 有几条数据

select count(age) from dstu;

求最大值

> select MIN(age) from dstu;

求最小值

select  MIN(age) from dstu;

求和

select  SUM(age)  from  dstu;

分级查询GROOP  BY

统计出现的次数,

select count(*) from stu GROUP BY tzid;      可以看成是查询每个科目的报名人数,

统计每个科目报名人数,

select tzid,count(sid) from stu group by tzid;

   科目   学生人数        学生表         科目

分组条件查询,having

select tzid as 科目,count(sid) as 学生人数 from stu group by tzid having 学生人数=2;

多表查询  (着想查询)

select * from dstu where age > 19.5;

子查询:

  一条语句结合两条语句,

select * from dstu where age > (select avg(age) from dstu);

着想查询:

  内连接 [INNER| CROSS] JOIN

同时查询二个表,

select * from tanzhou,stu;

select * from stu inner join tanzhou;

关联查询:

select * from stu inner join tanzhou on tzid=sid;

外连接 { LEFT| RIGHT } JOIN

select * from stu left  join dstu on id = sid;

与内连接相比,可以显示所有学生,包括未选课的学生,

作业;:

查询学生详情表性别为男,并年龄大于18,

select * from dstu where age>18 and sex='b';

在此基础上查改名,..

需求: 作为宿管,想知道学生的 ( 姓名, 年龄,性别,所属学

select  name js from 表单名 where js between 70 and 90 ;

找出分数在70到90的。

补充

潭州课堂25班:Ph201805201 MySQL第三课 (课堂笔记)的更多相关文章

  1. 潭州课堂25班:Ph201805201 WEB 之 页面编写 第四课 登录注册 (课堂笔记)

    index.html 首页 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  2. 潭州课堂25班:Ph201805201 WEB 之 页面编写 第三课 (课堂笔记)

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  3. 潭州课堂25班:Ph201805201 WEB 之 页面编写 第二课 (课堂笔记)

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  4. 潭州课堂25班:Ph201805201 WEB 之 页面编写 第一课 (课堂笔记)

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  5. 潭州课堂25班:Ph201805201 第十课 类的定义,属性和方法 (课堂笔记)

    类的定义 共同属性,特征,方法者,可分为一类,并以名命之 class Abc: # class 定义类, 后面接类名 ( 规则 首字母大写 ) cls_name = '这个类的名字是Abc' # 在类 ...

  6. 潭州课堂25班:Ph201805201 django 项目 第四十五课 mysql集群和负载均衡(课堂笔记)

    2.使用docker安装Haproxy 一.为什么要使用数据库集群和负载均衡? 1.高可用 2.高并发 3.高性能 二.mysql数据库集群方式 三.使用docker安装PXC 1.拉取PXC镜像 d ...

  7. c潭州课堂25班:Ph201805201 MySQL第二课 (课堂笔记)

    mysql> create table tb_2( -> id int, -> name varchar(10) not null -> ); 插入数据 insert into ...

  8. 潭州课堂25班:Ph201805201 MySQL第一课 (课堂笔记)

    一般说来,关系形在磁盘中,非关系表在内存中, 进入 MySQL: mysql -u用户名 -p密码 mysql -uroot -pqwe123 mysql -h127.0.1 -P3306 -uroo ...

  9. 潭州课堂25班:Ph201805201 django 项目 第五课 静态页面转为模板 (课堂笔记)

    一.分析静态页面   1.静态vs动态 条目 静态页面 动态页面 网站内容 固定不变 经常变动 浏览器加载速度 更快(无需向服务器发起请求) 更慢 改变网站内容 很难(修改或者创建新的html页面) ...

随机推荐

  1. Django中全局Context处理器

    1.模板标签和模板变量 模板标签在{% %}中定义: {% if is_logged_in %} Thanks for logging in! {% else %} Please log in. {% ...

  2. Async 详解

    一:流程控制 为了适应异步编程,减少回调的嵌套,我尝试了很多库.最终觉得还是async最靠谱. 地址:https://github.com/caolan/async Async的内容分为三部分: 流程 ...

  3. 『转载』Matlab中fmincon函数获取乘子

    Matlab中fmincon函数获取乘子 一.输出结构 [x,fval,exitflag,output,lambda] = fmincon(......) 二.结构说明 lambda结构 说     ...

  4. 【转】CString与string、char*的区别和转换

    我们在C++的开发中经常会碰到string.char*以及CString,这三种都表示字符串类型,有很多相似又不同的地方,常常让人混淆.下面详细介绍这三者的区别.联系和转换: 各自的区别 char*: ...

  5. client模式下对应接口加入桥接出错

    client模式下,响应的接口wlan0 加入桥接时出现如下错误: root@root:~# brctl addif br-lan wlan0brctl: bridge br-lan: Operati ...

  6. Qt5.8 在windows下mingw静态编译

    官方对编译一些条件介绍:https://doc.qt.io/qt-5/windows-requirements.html 在默认情况下,用QtCreator编译程序时,使用的是动态编译.编译好的程序在 ...

  7. 使用Navicat Premium对sqlserver 2008进行表、字段及用户权限的精细化管理

    在一些特殊的业务场景,我们需要对数据库进行精细化的管理,比如只能授权给某用户某个表的操作权限,最小权限法则可以保障数据库最大的安全.利用navicat这个轻量化的工具可以很轻松的解决这个问题 1.通过 ...

  8. Oracle数据库操作基本语法

    创建表 SQL>create table classes(        classId number(2),        cname varchar2(40),        birthda ...

  9. SonarQube代码质量管理工具的升级(sonarqube6.2 + sonar-scanner-2.8 + MySQL5.6+)

    SonarQube升级注意事项 0. 前提条件 如果之前是使用sonarqube5.2 + sonar-runner-2.4 +MySQL5.5版本或者类似的组合. 安装方法请参照SonarQube代 ...

  10. 【ES】学习1-入门使用

    参考资料: https://elasticsearch.cn/book/elasticsearch_definitive_guide_2.x/_search_lite.htm 1.查询es数据的方法 ...