
复制/*with查询*/              declare @withquery varchar(5000)              declare @execcount int=0              set @withquery=with TheseEmployees as(              select empid from hr.employees where country=NUSA),点滴
              CharacteristicFunctions as(              select custid,              casewhen custid in (select custid from sales.orders as o where o.empid=e.empid) then 1 else 0 endas charfun              from sales.customers as c crossjoin TheseEmployees as e)              select custid from CharacteristicFunctions groupby custid havingmin(charfun)=1 orderby custid              while @execcount<10              begin            exec (@withquery);              set @execcount=@execcount+1              end            /*子查询*/              declare @subquery varchar(5000)              declare @execcount int=0              set @subquery=select custid from Sales.Orders where empid in            (select empid from HR.Employees where country = NUSA) groupby custid              havingcount(distinct empid)=(selectcount(*) from HR.Employees where country = NUSA);              while @execcount<10              begin            exec (@subquery);              set @execcount=@execcount+1              end            1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.