第13章:分组过滤。

P83

select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值#

P84

select count(*) as num_prods from products group by vend_id; #返回各个vend_id所提供的产品数量,不需要指定计算每个组,因为用了group by ,系统会自动完成#

注意:group by必须在where 之后,order by 之前(当然是在需要where 或order by 的情况下)

P85

select vend_id,count(*) as num_prods from products group by vend_id with rollup ;  # 使用with rollup关键字,可以得到每个分组以及每个分组汇总级别(针对每个分组)的值###其实我觉得使用了with rollup与否,对结果并没有影响,来个可爱告诉我使用不使用的区别吧###

P85 过滤分组 -- having语句

select cust_id,count(*) as orders from orders group by cust_id having count(*)>=2l; #where 过滤行,having过滤分组###我理解的是where对表初始的行数据过滤,而having是聚集函数处理以后的分组过滤(感觉不大对)#####对面大神说用了group by了不能用where,要用having。(P87页说和聚集函数一起使用列,必须使用group by,不能使用order by ,相应地,下面的csdn的网友说,聚集函数要用having筛选分组,所以以此类推,用了group by不能用where,要用having的意思吗??? )###

P86

select vend_id,count(*) as num_prods from products where prod_price>=10 group by vend_id having count(*)>=2;  #条件是列prod_price>=10,count(*)>=2 ,这个语句同时出现where和having #

有个我认为不错的解释:https://blog.csdn.net/zqtsx/article/details/41869049

P88

select order_num,sum(quantity*item_price) as ordertotal from orderitems group by order_num having sum(quantity*item_price)>=50; #group by 让排列按order_num来排列,having设定了组sum(quantity*item_price)或者是ordertotal大于50的条件.

select order_num,sum(quantity*item_price) as ordertotal from orderitems group by order_num having sum(quantity*item_price)>=50 order by ordertotal ; #group by 让排列按order_num来排列,having设定了聚集函数得到的组sum(quantity*item_price)大于等于50,order by 得到最后的顺序由ordertotal排序输出(ordertatal的顺序默认是升序)#.

#group by 分组说明,仅限于聚集函数得到的分组;

having :组级过滤;

where:行级过滤,表中的行;

order by :输出的排序过滤。

limit n :要检索的行数;

limit (n,m) :要检索的(开始的行数:第n个开始,检索m行即是第n+m个结束)#

《mysql必知必会》学习_第13章_20180803_欢的更多相关文章

  1. 《mysql必知必会》学习_第18章_20180807_欢

    第18章 全文本搜索 P121  #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引# create table productnotes ( note_id  int   NOT ...

  2. 《mysql必知必会》学习_第五章_20180730_欢

    使用的工具是wamp的Mysql. P29 select prod_name from products;  #在表products中选列prod_name,顺寻不是纯粹的随机,但是没有说明排列顺序, ...

  3. 《mysql必知必会》学习_第22章_20180809_欢

    第22章:使用视图,视图是虚拟的表,以表形式呈现的是你查询的结果.并不是说在数据库里面真的存在这个表,但是是真的存在这些数据. select cust_name,cust_contact from c ...

  4. 《mysql必知必会》学习_第20章_20180809_欢

    第20章:更新和删除数据 P140 update customers set_emails='elmer@fudd.com' where cust_id=10005; 更新多个列,用逗号隔开.注意被指 ...

  5. 《mysql必知必会》学习_第19章_20180809_欢

    第19章 插入数据 P132 insert into customers VALUES(NULL,'Pep E.Lapew','100 Main Street',,Los Angeles','CA', ...

  6. 《mysql必知必会》学习_第17章_20180807_欢

    第17章:组合查询 P114 select vend_id ,prod_id,prod_price from products where prod_price <=5 ; select ven ...

  7. 《mysql必知必会》学习_第16章_20180807_欢

    第16章:创建高级联结. P106 select concat(RTrim(vend_name),'(',RTrim(vend_country),')') as vend_title from ven ...

  8. 《mysql必知必会》学习_第15章_20180806_欢

    第15章:联结表 P98 外键:外键为某个表的一列A,同时这一列包含另一个表的主键值B(B属于A,等于或者小于的关系) P99 select vend_name,prod_name,prod_pric ...

  9. 《mysql必知必会》学习_第14章_20180806_欢

    第14章:使用子查询. 子查询是镶嵌在其他查询里面,相当其他的select查询的条件来. P91 select order_num from where prod_id='tnt2';   #检索条件 ...

随机推荐

  1. 4K - 找新朋友

    新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道 ...

  2. 使用开源的工具解析erspan流量

    Decapsulation ERSPAN Traffic With Open Source Tools Posted on May 3, 2015 by Radovan BrezulaUpdated ...

  3. 一个比较有意思的SDN网络技术相关blog/doc

    http://feisky.xyz/sdn/linux/index.html 涵盖了目前主流的网络技术,所有比较有意思的内容全都覆盖了 SDN网络 目录 基本网络 TCP/IP标准模型 DHCP与DN ...

  4. 20172306《Java程序设计》第四周学习总结

    20172306 <Java程序设计>第四周学习总结 教材学习内容总结 第四章: 1. 类和对象的回顾:除了看书,我还上网找了一下两者的一些区别. 2. 编写类时,了解到初始化.形式参数. ...

  5. TCHAR函数查询

    https://blog.csdn.net/is2120/article/details/27542927

  6. Creating Your Own PHP Helper Functions In Laravel

    By Hamza Ali LAST UPDATED AUG 26, 2018  12,669 104 Laravel provides us with many built-in helper fun ...

  7. win10无法访问别的机器的共享目录

    Win + R 输入 regedit Open Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstat ...

  8. eclipse中tomcat调试正确关联源码

    1.build path中jar包关联本地源码 2.tomcat中添加source关联工程lib下的jar包 以上两步即可. 可解决tomcat直接关联本地源码debug时无法计算表达式的情况. 错误 ...

  9. APICloud开发

    2018-06-16 今天在看房角石APPIOS版本闪退的问题,后来定位到了 elements.find("video").attr("preload", &q ...

  10. Vue 使用中的小技巧

    在vue的使用过程中会遇到各种场景,当普通使用时觉得没什么,但是或许优化一下可以更高效更优美的进行开发.下面有一些我在日常开发的时候用到的小技巧,在下将不定期更新~ 1.多图表resize事件去中心化 ...