第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. 200. Spring Boot JNDI:在Tomcat中怎么玩JNDI?

      [视频&交流平台] àSpringBoot视频:http://t.cn/R3QepWG à SpringCloud视频:http://t.cn/R3QeRZc à Spring Boot源 ...

  2. 二、Jmeter脚本开发

    目录 1.Jmeter协议录制 1.Jmeter协议录制 1.1 dboy进行录制 badboy下载地址:http://www.badboy.com.au/download/add badboy是一个 ...

  3. Spring -- <tx:annotation-driven>注解基于JDK动态代理和CGLIB动态代理的实现Spring注解管理事务(@Trasactional)的区别。

    借鉴:http://jinnianshilongnian.iteye.com/blog/1508018 基于JDK动态代理和CGLIB动态代理的实现Spring注解管理事务(@Trasactional ...

  4. show出相应单据列表

    var Fids=AddGroupItems.Select(o=>Convert.ToString(o["Id"])).ToArray(); string filter=st ...

  5. 子类中加virtual 有用没?多重继承的机制 还需要再探!

    class D:public C{ public: D(){cout << "D()" << endl;} virtual ~D(){ cout <& ...

  6. tcp中delay_ack的理解

    内核版本,3.10. 首先,我们需要知道,在一个sock中,维护ack的就有很多变量,多种状态: struct inet_connection_sock { .... __u8 icsk_ca_sta ...

  7. MYSQL性能优化(1)

    优化步骤 1.show status 查询服务器状态运行信息 根据增删改查统计信息可以知道数据库是查询为主还是更新为主,各类型业务大致比例(更新操作 执行与回滚都会计数) 对于事务,可以通过Com_c ...

  8. python学习Day1 计算机原理编程思维

    一.学习思想:3W+1H   学什么(what).为什么学(why).用在哪里(where).怎么用(how) 学习编程语言重在代码量.代码量.代码量! 二.计算机五大组成部分,三大核心: 五大组成部 ...

  9. CSS 表单

    输入框前有图片 老板让你实现在输入框前有图片的功能.老板觉得用图片代替文字更有说服力. 要实现这样的功能很简单,它的原理是将图片放在内边距内. 代码 1 2 3 4 5 6 7 8 9 10 11 1 ...

  10. [转]MAC系统下Sublime Text3 配置Python3详细教程(亲测有效)

    原文地址: https://blog.csdn.net/weixin_41768008/article/details/79859008?tdsourcetag=s_pctim_aiomsg 这段时间 ...