《mysql必知必会》学习_第17章_20180807_欢
第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_欢的更多相关文章
- 《mysql必知必会》学习_第18章_20180807_欢
第18章 全文本搜索 P121 #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引# create table productnotes ( note_id int NOT ...
- 《mysql必知必会》学习_第16章_20180807_欢
第16章:创建高级联结. P106 select concat(RTrim(vend_name),'(',RTrim(vend_country),')') as vend_title from ven ...
- 《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必知必会》学习_第15章_20180806_欢
第15章:联结表 P98 外键:外键为某个表的一列A,同时这一列包含另一个表的主键值B(B属于A,等于或者小于的关系) P99 select vend_name,prod_name,prod_pric ...
- 《mysql必知必会》学习_第14章_20180806_欢
第14章:使用子查询. 子查询是镶嵌在其他查询里面,相当其他的select查询的条件来. P91 select order_num from where prod_id='tnt2'; #检索条件 ...
- 《mysql必知必会》学习_第13章_20180803_欢
第13章:分组过滤. P83 select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值 ...
随机推荐
- suricata 配置文件threshold
threshold threshold(阈值)关键字可用于控制规则的警报频率,它有3种模式: threshold: type <threshold|limit|both>, track & ...
- Creating adaptive web recommendation system based on user behavior(设计基于用户行为数据的适应性网络推荐系统)
文章介绍了一个基于用户行为数据的推荐系统的实现步骤和方法.系统的核心是专家系统,它会根据一定的策略计算所有物品的相关度,并且将相关度最高的物品序列推送给用户.计算相关度的策略分为两部分,第一部分是针对 ...
- leetcode461
public class Solution { public int HammingDistance(int x, int y) { ]; ]; ; ; do { aryA[i] = x % ;//将 ...
- Mysql 和 SQLServer 使用SQL差异比较
查询前100条数据 #mysql ; #sqlserver * from table_name ; 从数据库.表 定位表 #mysql写法:库名.表名 select password from Inf ...
- canvas 2.0 图片绘制
绘制图片drawImage 2013.02.21 by 十年灯·一条评论 本文属于<html5 Canvas画图系列教程> 这里的绘制图片是指把一张现成的图片,绘制到Canvas上面. 有 ...
- Rabbitmq 与springboot 结合
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- mysql 使用注意
1. consider upgrading MySQL client 描述:因mysql5版本过度到8版本后,访问要求升级mysql的客户端 原因:mysql在升级后,对加密算法部分做了调整导致. 对 ...
- 移动端UL列表无法平滑向下滚动问题
问题说明: 移动端向上滑动后,,列表无法自动滚动到底部~~而是类似屏幕"沾手"的效果(手离开屏幕直接停止在当前~列表不会自动向下滚动一段) 问题原因: 页面中存在如下代码: 当前页 ...
- java学习--异常
异常的概念 java异常是java提供的用于处理程序中错误的一种机制 所谓的错误是指在程序运行过程中发生的一些异常事件.如除0溢出,数组下标越界,文件不存在 设计良好的程序应该在异常发生时,提供处理这 ...
- python sqlparse 各种 token
https://blog.csdn.net/qq_39607437/article/details/79620383 import sqlparse def look(statement): prin ...