IT科技

SQL点滴之with语句和子查询的性能比较

字号+作者:益华科技来源:应用开发2025-11-05 01:23:24我要评论(0)

复制/*with查询*/ declare@withqueryvarchar(5000) declare@execcountint=0

SQL点滴之with语句和子查询的性能比较
复制/*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.

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • iOS11Beta1(探索iOS11Beta1带来的全面升级和创新特性)

    iOS11Beta1(探索iOS11Beta1带来的全面升级和创新特性)

    2025-11-05 00:10

  • MySQL select技巧使用大全

    MySQL select技巧使用大全

    2025-11-04 23:17

  • vsftpd+MySQL创建虚拟用户在Debian Linux之下

    vsftpd+MySQL创建虚拟用户在Debian Linux之下

    2025-11-04 23:05

  • 如何在CU上整理MySQL常见的某些问题

    如何在CU上整理MySQL常见的某些问题

    2025-11-04 23:05

网友点评