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

  • 相关阅读:
    每日日报
    HTML相关
    60-Shiro功能扩展(记住我)
    60--Shiro安全框架
    服务器项目部署简单操作
    61--DB项目--修改密码模块设计
    59-SpringAOP --Cache操作(注解)
    58-Spring AOP 异步操作
    58-Spring-AOP事务管理
    Terminal 执行 java 命令
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3407931.html
Copyright © 2011-2022 走看看