zoukankan      html  css  js  c++  java
  • T-SQL基础(4)

    简单子查询
    select * from (select custid, companyname from Sales.Customers where country = N'USA') as USACusts

    关联子查询
    select custid, orderid, orderdate, empid
    from Sales.Orders as o1
    where orderid = (select max(o2.orderid)
                        from Sales.Orders as o2
                        where o2.custid = o1.custid)

    select orderid, custid, val,
    cast(100 * val / (select sum(o2.val)
                        from Sales.OrderValues as o2
                        where o2.custid = o1.custid)
                        as numeric(5,2))
    as pct
    from Sales.OrderValues as o1
    order by custid, orderid;

    select custid, companyname
    from Sales.Customers as c
    where country = N'Spain' and exists
    (select * from Sales.Orders as o where o.custid = C.custid)

    高级子查询
    select orderid, orderdate, empid, custid,
    (
        select max(o2.orderid)
        from Sales.Orders as o2
        where o2.orderid < o1.orderid
    )
    as prevorderid
    from Sales.Orders as o1

  • 相关阅读:
    12迭代器
    11(2)Vector(向量)
    11(1) LinkList ---链表
    11集合(Collection<E>) Arraylist
    10异常
    乘法计算过程的模拟
    10 Date详解
    详细的OA系统学习
    8 math类
    Java开发中的23种设计模式详解
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3407931.html
Copyright © 2011-2022 走看看