《mysql必知必会》学习_第12章_20180801_欢
第12章:汇总数据
P76 avg()函数求平均值
select avg(prod_price) as avg_price from products; #计算prod_price的平均值,并且命名为avg_price#

select avg(prod_price) as avg_price from products where vend_id=1003; #计算priod_id=1003的prod_price的平均值,并且命名为avg_price#

select count(*) as num_cust from customers; #通配符*表示选中所有行,包括空值,返回是行数。#

select count(cust_email) as num_cust from customers; #计算行cust_email的个数,不包括空值#

select max(prod_price) as max_price from products; #max()计算列prod_price的最大数#

P79 min()函数用来计算最小值,经常也计算最初的时间。
select min(prod_price) as min_price from products; #计算prod_price的最小值,并命名为min_price#

select sum(quantity) as items_ordered from orderitems where order_num=2005; #sum()函数计算括号里面的列中订单号码等于20005的数值的总值#

P80
select sum(quantity*item_price) as total_price from orderitems where order_num=2005; #sum()函数计算括号里面的列中订单号码等于20005的数值的总值#

P81 聚集不同值
select avg(distinct prod_price) as avg_price from products where vend_id=1003; #distinct 表示去掉重复值,然后再求去掉重复值之后的平均值,并命名为avg_price ,条件是vend_id=1003#

注意:没有count(distinct)的使用,有distinct(count)的使用。
select count(*) as num_items, min(prod_price) as price_min,max(prod_price) as price_max,avg(prod_price) as price_avg from products; #一个语句中同时出现几个语句#

《mysql必知必会》学习_第12章_20180801_欢的更多相关文章
- 《mysql必知必会》学习_第11章_20180801_欢
第11章:使用数据处理函数. P69 文本处理函数,upper()函数把文本变成大写字体. select vend_name,upper(vend_name) as vend_name_upcase ...
- 《mysql必知必会》学习_第18章_20180807_欢
第18章 全文本搜索 P121 #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引# create table productnotes ( note_id int NOT ...
- 《mysql必知必会》学习_第五章_20180730_欢
使用的工具是wamp的Mysql. P29 select prod_name from products; #在表products中选列prod_name,顺寻不是纯粹的随机,但是没有说明排列顺序, ...
- 《mysql必知必会》学习_第22章_20180809_欢
第22章:使用视图,视图是虚拟的表,以表形式呈现的是你查询的结果.并不是说在数据库里面真的存在这个表,但是是真的存在这些数据. select cust_name,cust_contact from c ...
- 《mysql必知必会》学习_第20章_20180809_欢
第20章:更新和删除数据 P140 update customers set_emails='elmer@fudd.com' where cust_id=10005; 更新多个列,用逗号隔开.注意被指 ...
- 《mysql必知必会》学习_第19章_20180809_欢
第19章 插入数据 P132 insert into customers VALUES(NULL,'Pep E.Lapew','100 Main Street',,Los Angeles','CA', ...
- 《mysql必知必会》学习_第17章_20180807_欢
第17章:组合查询 P114 select vend_id ,prod_id,prod_price from products where prod_price <=5 ; select ven ...
- 《mysql必知必会》学习_第16章_20180807_欢
第16章:创建高级联结. P106 select concat(RTrim(vend_name),'(',RTrim(vend_country),')') as vend_title from ven ...
- 《mysql必知必会》学习_第15章_20180806_欢
第15章:联结表 P98 外键:外键为某个表的一列A,同时这一列包含另一个表的主键值B(B属于A,等于或者小于的关系) P99 select vend_name,prod_name,prod_pric ...
随机推荐
- 安全概念:DMZ(非军事化区,隔离区)
DMZ是英文“demilitarized zone”的缩写,中文名称为“隔离区”,也称“非军事化区”.它是为了解决安装防火墙后外部网络不能访问内部网络服务器的问题,而设立的一个非安全系统与安全系统之间 ...
- MAC/Xcode简单操作命令
快捷键: command(windows) + c: 复制 command + V : 粘贴 command + x: 剪切(只在当前应用程序内有效) 在mac系统下表示剪切功能: 先command ...
- export export defalut
require/exports 和 import/export 形式不一样 require/exports 的用法只有以下三种简单的写法: const fs = require('fs') expor ...
- java中 this 关键字的三种用法
Java中this的三种用法 调用属性 (1)this可以调用本类中的任何成员变量 调用方法(可省略) (2)this调用本类中的成员方法(在main方法里面没有办法通过this调用) 调用构造方法 ...
- ubuntu下firefox打开mht文件
1.安装firefox插件:UnMHT 插件地址:http://www.unmht.org/unmht/en_index.html 2.用firefox打开mht文件
- 杭电1518 Square(构成正方形) 搜索
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 重新设置Linux的IP地址(该操作会永久更改ip地址)
1.查看你当前的IP地址 2.进入配置文件进行更改IP地址 3.上图我使用的是ifcfg-eth1 ,然后进行更改这个文件 4.点击“insert”进行编辑改文档,吧对应的IP改成你想要的地址 更改完 ...
- IOS初级:SDWebImage
简单用法 #import "ViewController.h" #import "SDWebImage/UIImageView+WebCache.h" @int ...
- 记录一次JVM调优【GC日志的分析】
首先查看服务器版本默认信息: 修改tomcat/bin/catalina.sh,在最顶端加入JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails -Xloggc ...
- bootstrap 中 css 与 javascript 的使用
1.css 1.1.选择器 1.2.子选择器: css 里的子元素用符号'>'表示.如下示例是表示拥有table样式的表盒,其thead元素内的tr元素如果有th的话,则应用该样式. .tabl ...