|
| » 首页 » 电脑_数码 » 编程 » 请高手帮忙优化一下这条SQL语句 |
请高手帮忙优化一下这条SQL语句 |
|
A表样式: 10629625 8826512201248 10325335752 10629625123 103253353752 …… B表样式 10629 103253 88265122 …… 我的语句是这样的select a.col001 into C from A a,B where left(a.col002,len(B.col001))=B.col001 ,不过数据比较大,执行起来很慢,有没有高手帮一下要怎样优化这条语句,谢谢了 |
![]() |
|
|
0-1之间类似于 program test implicit none real :: x call random_seed()! 系统根据日期和时间随机地提供种子" call random_number(x) print *,x end program 另外,在一个程序中, "call random_seed () 这一句是不能重复的,只能用一次。 所以它不能放到循环里面去,另外,如果一个子程序会被调用多次的话,也不能放到子程序里面。 ============== 如果你非得用rand()的话,看看这个帖子吧: http://bbs.pfan.cn/post-276179.html 用存储过程。。。。 写一个函数. 把A表,循环用函数对比就比你哪个快多了! use tempdb create table a(a bigint) create table b(b bigint) insert into a select 10629625 union all select 8826512201248 union all select 10325335752 union all select 10629625123 union all select 103253353752 insert into b select 10629 union all select 103253 union all select 88265122 select * from a select * from b select distinct cast(b.b as varchar) into c from a,b where cast(a.a as varchar) like (cast(b.b as varchar) + '%') select * from c 要用到储存过程和游标(有小小难度) if exists(select * from sysobjects where name='aa' and type='p') drop proc aa go create proc aa as declare @s varchar(20) declare t cursor for select n from b open t fetch next from t into @s --set @s=rtrim(@s)+'%' select * from a where N like rtrim(@s)+'%' while @@fetch_status=0 begin fetch next from t into @s select * from a where N like rtrim(@s)+'%' end close t deallocate t go |
| 《请高手帮忙优化一下这条SQL语句》答案收集时间:2008-06-14 14:28:19 |