《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的产品数目总值 ...
随机推荐
- jquery中live is not a function的问题
jquery中的live()方法在jquery1.9及以上的版本中已被废弃了,如果使用,会抛出TypeError: $(...).live is not a function错误. 解决方法: 之前的 ...
- Android开发中常见的设计模式(四)——策略模式
策略模式定义了一些列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变换. 假设我们要出去旅游,而去旅游出行的方式有很多,有步行,有坐火车,有坐飞机等等 ...
- 使用Nexus2搭建Maven本地仓库
由于OS为WindowsXP,而Nexus3forWindows为x64版本,只能选择安装nexus2了. Windows(x86)平台,Nexus Repository Manager OSS 2. ...
- RGB颜色值转化为long 型数字
通常我们表达颜色都是使用RGB值表示的,今天在VB中设置RGB值居然是一个整形数字,网上各种搜资料发现这个数字是怎么来的: 数值= 65536*Blue + 256* Green + Red
- ODPS SQL <for 数据操作语言DML>
基本操作: 查询: SELECT [ALL | DISTINCT] select_expr, select_expr, ... FROM table_reference [WHERE where_co ...
- 安装Python-Jenkins
有两种方式安装: ①有网络:sudo pip install python-jenkins ②无网络: 下载文件:https://pypi.org/project/python-jenkins/#fi ...
- 89. Gray Code返回位运算的所有生成值
[抄题]: The gray code is a binary numeral system where two successive values differ in only one bit. G ...
- 8. String to Integer (atoi) 字符串转成整数
[抄题]: Input: "42" Output: 42 Example 2: Input: " -42" Output: -42 Explanation: T ...
- LAB2
任务1: 效果:HelloWorld 好像完全按视频做就行了 学会了:把glassfish改好了,能跑 没学会:视频里的解说不懂在干嘛,得再看看 任务2 效果:intersetingpicture要求 ...
- Git常用命令及场景
Git命令推送到远程分支 1.登录GitHub创建一个远程仓库. https://github.com 2.git init 本地创建一个目录,并初始化一个git仓库. 3.git add 添加文件到 ...