潭州课堂25班:Ph201805201 MySQL第三课 (课堂笔记)
单表查询:
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第三课 (课堂笔记)的更多相关文章
- 潭州课堂25班:Ph201805201 WEB 之 页面编写 第四课 登录注册 (课堂笔记)
index.html 首页 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- 潭州课堂25班:Ph201805201 WEB 之 页面编写 第三课 (课堂笔记)
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 潭州课堂25班:Ph201805201 WEB 之 页面编写 第二课 (课堂笔记)
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 潭州课堂25班:Ph201805201 WEB 之 页面编写 第一课 (课堂笔记)
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 潭州课堂25班:Ph201805201 第十课 类的定义,属性和方法 (课堂笔记)
类的定义 共同属性,特征,方法者,可分为一类,并以名命之 class Abc: # class 定义类, 后面接类名 ( 规则 首字母大写 ) cls_name = '这个类的名字是Abc' # 在类 ...
- 潭州课堂25班:Ph201805201 django 项目 第四十五课 mysql集群和负载均衡(课堂笔记)
2.使用docker安装Haproxy 一.为什么要使用数据库集群和负载均衡? 1.高可用 2.高并发 3.高性能 二.mysql数据库集群方式 三.使用docker安装PXC 1.拉取PXC镜像 d ...
- c潭州课堂25班:Ph201805201 MySQL第二课 (课堂笔记)
mysql> create table tb_2( -> id int, -> name varchar(10) not null -> ); 插入数据 insert into ...
- 潭州课堂25班:Ph201805201 MySQL第一课 (课堂笔记)
一般说来,关系形在磁盘中,非关系表在内存中, 进入 MySQL: mysql -u用户名 -p密码 mysql -uroot -pqwe123 mysql -h127.0.1 -P3306 -uroo ...
- 潭州课堂25班:Ph201805201 django 项目 第五课 静态页面转为模板 (课堂笔记)
一.分析静态页面 1.静态vs动态 条目 静态页面 动态页面 网站内容 固定不变 经常变动 浏览器加载速度 更快(无需向服务器发起请求) 更慢 改变网站内容 很难(修改或者创建新的html页面) ...
随机推荐
- 【shell】查找后拷贝find . -name *.csv -exec cp {} /home/ \;
Find命令的一般形式为: find pathname -options [-print -exec -ok] 让我们来看看该命令的参数: pathname: find命令所查找的目录路径.例如用.来 ...
- HTML学习笔记07-头部
HTML <head> 元素 <head> 元素包含了所有的头部标签元素.在 <head>元素中你可以插入脚本(scripts), 样式文件(CSS),及各种met ...
- 利用autocomplete.js实现仿百度搜索效果(ajax动态获取后端[C#]数据)
实现功能描述: 1.实现搜索框的智能提示 2.第二次浏览器缓存结果 3.实现仿百度搜索 <!DOCTYPE html> <html xmlns="http://www.w3 ...
- ORA-01017: invalid username/password; logon denied 解决方案
在SQLPLUS窗口下进行用户登录,出现ORA-01017:invalid username/password:logon denied .如下图: 在网上找了很久,发现一个实用的解决方案,操作如下: ...
- linux 平台core dump文件生成
1. 在终端中输入ulimit -c 如果结果为0,说明当程序崩溃时,系统并不能生成core dump. root@hbg:/# ulimit -c0root@hbg:/# 2.使用ulimit -c ...
- saltstack自动化运维系列②之saltstack的数据系统
saltstack自动化运维系列②之saltstack的数据系统 grains:搜集minion启动时的系统信息,只有在minion启动时才会搜集,grains更适合做一些静态的属性值的采集,例如设备 ...
- windows service 的错误 错误 14001:
1.Windows服务启动时报:“错误 14001:由于应用程序配置不正确,应用程序未能启动.重新安装应用程序可能会纠正这个问题.”的错误. 原因:Windows 服务程序 配置文件中 <a ...
- linux下各目录的作用
这么久了,一直觉得对于linux的运作情况还是懵懵懂懂的样子,刚才专门又看了一下 linux 下各目录的作用,记下来,以备以后再忘了. 下面内容来自:http://www.linuxidc.com/L ...
- listbox或datagrid内容双击事件绑定
====listbox=== <DataTemplate> <Border Width="350" Height="230" Margin=& ...
- 有关cookie
cookie 会话跟踪技术 <script> /* cookie 全称 会话跟踪技术. ...