《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 ...
随机推荐
- python添加fluent日志记录-aop
python添加fluent日志,aop实现 1.配置fluent相关信息 fluent_config.ini fluent_config.ini [fluent.aop] #is support f ...
- hdu 1026(BFS+输出路径) 我要和怪兽决斗
http://acm.hdu.edu.cn/showproblem.php?pid=1026 模拟一个人走迷宫,起点在(0,0)位置,遇到怪兽要和他决斗,决斗时间为那个格子的数字,就是走一个格子花费时 ...
- [Centos] ERROR: Could not find useradd in chroot, maybe the install failed?
[mockbuild at localhost ~]$ mock -r centos-5-x86_64-testdev.cfg initinitcleanprepThis may take a whi ...
- 使用limma、Glimma和edgeR,RNA-seq数据分析易如反掌
使用limma.Glimma和edgeR,RNA-seq数据分析易如反掌 Charity Law1, Monther Alhamdoosh2, Shian Su3, Xueyi Dong3, Luyi ...
- .net委托
今天要学的是委托 委托的基本形式 直接上代码 public delegate int AddDelegate(int x,int y); class Program { static void Mai ...
- BZOJ1855 股票交易 单调队列优化 DP
描述 某位蒟佬要买股票, 他神奇地能够预测接下来 T 天的 每天的股票购买价格 ap, 股票出售价格 bp, 以及某日购买股票的上限 as, 某日出售股票上限 bs, 并且每次股票交 ♂ 易 ( 购 ...
- django数据库多对多修改对应关系
obj = models.Book.objects.get(id=1) #添加对应关系,给书添加作者# obj.m.add(3)# obj.m.add(2,4)# obj.m.add(*[1,2,3, ...
- 把dataset对象转换成list集合方法
public static List<T> GetList<T>(DataTable table) where T:new() { List<T> list = n ...
- maven下载的jar相应pom文件下载不完整问题。
今天遇到一个奇葩问题: 同样的项目,我启动报错 : 某个class文件找不到.. 查找maven 依赖也的确没有找到 对应的jar 包. 查找同事项目,可以看到该class对应的 jar 包 是 lo ...
- canvas 实现圆环效果
var race = document.getElementById('race'); var cxt = race.getContext('2d'); var ang = 0; var speed ...