zoukankan      html  css  js  c++  java
  • 《mysql必知必会》学习_第17章

    第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语句之后 #

     

  • 相关阅读:
    Dockerfile构建基础镜像为alpine的jdk1.8镜像
    app测试01_app测试漫谈
    ES基本操作命令
    springboot 前后端日期json格式化
    降维处理PCA
    分析鸢尾花数据集
    Python--matplotlib绘图可视化知识点整理
    模拟股票预期收益案例源代码
    np.random.normal()正态分布
    pandas
  • 原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9439421.html
Copyright © 2011-2022 走看看