zoukankan      html  css  js  c++  java
  • sql查询:联合查询

    --使用Northwind
    --连接查询
    --内连接(Inner Join)
    select  p.* from  Products p inner join [Order Details] o on p.ProductID=o.ProductID 
    go
    select  p.*,c.* from  Products p inner join Categories c on c.CategoryID=p.CategoryID 
    go
      
    --1、左外连接
    select  p.*,c.* from Categories c  left outer join Products p on p.CategoryID=c.CategoryID  order by p.ProductID
    --2、右外连接
    select  p.*,c.* from Categories c  right outer join Products p on p.CategoryID=c.CategoryID  order by p.ProductID
    --3、全外连接
    select  p.*,c.* from Categories c  full outer join Products p on p.CategoryID=c.CategoryID  order by p.ProductID
    --子查询
      
    --1、使用比较运算符的子查询
    select * from Products  where unitprice>(select avg(unitprice) from Products)
    --2、使用IN的子查询
    select * from Products where categoryID in (select categoryID from categories)
    --3、使用some和any的子查询
      
    select * from Products  where unitprice<some(select avg(unitprice) from Products)
      
      
      
    --4、使用All的子查询
    select * from Products  where unitprice<>All(select avg(unitprice) from Products)
      
    --5、使用Exists的子查询
    select * from Products where  exists (select * from categories where categories.categoryID=Products.categoryID and categories.categoryID=2)
  • 相关阅读:
    Windows环境下 配置memcached (php)
    谈谈我是怎么学习PHP的(一)
    重编译Linux命令源代码
    php面向对象学习
    Windows文件系统漏洞
    十分钟能学会的框架,MVC+20个常用函数
    linux系统安装软件方法大全
    oracle基本操作
    MySQL的limit查询优化
    C# winform 可视化操作 Excel文件并读取数据
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/2010753.html
Copyright © 2011-2022 走看看