第17章:组合查询

P114

select vend_id ,prod_id,prod_price from products where prod_price <=5 ;

select vend_id ,prod_id,prod_price from products where vend_id in (1001,1002);

P115 组合上面的两个语句。

select vend_id ,prod_id,prod_price from products where prod_price <=5 union  select vend_id ,prod_id,prod_price from products where vend_id in (1001,1002); #可以看到,结果是上面两个语句的结果的和(去掉重复值),相当把两个程序使用or语句#

P116 union必须有多个select语句组成,并且每个列都包含相同的列,表达式或者聚集函数(#不懂这句话,我感觉列名一样就可以了,求解???#)

另外,union自动去重处理结果。如果不需要去重,那用union all

select vend_id ,prod_id,prod_price from products where prod_price <=5 union all  select vend_id ,prod_id,prod_price from products where vend_id in (1001,1002);

P117

select vend_id ,prod_id,prod_price from products where prod_price <=5 union all  select vend_id ,prod_id,prod_price from products where vend_id in (1001,1002) order by vend_id,prod_price;  #使用union组合查询时,只能使用order by 自居,而且,order by 只能出现在最后一个select语句之后 #

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. 《mysql必知必会》学习_第13章_20180803_欢

    第13章:分组过滤. P83 select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值 ...

随机推荐

  1. django之Models和ORM

    ORM Object Relational Mapping,简称ORM,是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 通过使用描述对象和数据库之间映射的元数据,将程序中的对象自动持久 ...

  2. profile default

    SAPDBHOST = 10.199.0.26 j2ee/dbtype = hdb j2ee/dbname = ISD j2ee/dbhost = 10.199.0.26 dbs/hdb/dbname ...

  3. c#中使用excel

    在做一个小项目,需要把一些查询结果导出到Excel,找了一些资料,自己也总结出了一点方法,与大家共享. 一.首先简要描述一下如何操作Excel表 先要添加对Excel的引用.选择项目-〉添加引用-〉C ...

  4. leetcode621

    public class Solution { public int LeastInterval(char[] tasks, int n) { Dictionary<char, int> ...

  5. AR涂涂乐

    <1> 涂涂乐着色 https://blog.csdn.net/begonia__z/article/details/51282932 http://www.manew.com/blog- ...

  6. jQuery之必会增删改查Dom操作

    .next  .prev <button>change</button> <span class = '.demo'>aaa</span> <p ...

  7. electron-vue 淘宝源

    yarn-js config set registry https://registry.npm.taobao.org

  8. Java 虚拟机概述

    虚拟机是一种抽象化的计算机,通过在实际的计算机上仿真模拟各种计算机功能来实现的.Java虚拟机有自己完善的硬体架构,如处理器.堆栈.寄存器等,还具有相应的指令系统.Java虚拟机屏蔽了与具体操作系统平 ...

  9. day37 异步回调和协程

    异步回调 """ 异步任务使用场景 爬虫 1.从目标站点下载网页数据 本质就是HTML格式字符串 2.用re从字符串中提取出你需要的数据 ""&quo ...

  10. C语言变量声明内存分配

    转载: C语言变量声明内存分配   一个由c/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 程序运行时由编译器自动分配,存放函数的参数值,局部变量的值等.其操作方式类似于数据结 ...