• 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

  • 相关阅读:
    weblogic内存快速配置
    weblogic优化参数
    weblogic10.3.6忘记用户名或者密码的解决方法
    Linux shell 环境变量及有效范围
    linux文本处理常用命令
    Scala实践7
    Scala实践5
    Scala实践4
    Scala实践3
    Scala实践2
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3407931.html
Copyright © 2020-2023  润新知