日期:2014-05-17 浏览次数:20578 次
select b.name,sum(a.num)
from a,b
where (b.ifok = 1 and a.web = b.web)
or (b.ifok = 0 and a.web like b.web
------解决方案--------------------
'%')
if OBJECT_ID('tempdb..#temp', 'u') is not null drop table #temp;
go
create table #temp( [web] varchar(100), [num] int);
insert #temp
select 'http://xxx.com/1','10' union all
select 'http://xxx.com/1/2','5' union all
select 'http://xxx.com','30' union all
select 'http://xxx.com/3/1','10' union all
select 'http://xxx.com/3/2','11'
if OBJECT_ID('tempdb..#tempB', 'u') is not null drop table #tempB;
go
create table #tempB( [name] varchar(100), [web] varchar(100), [ifok] bit);
insert #tempB
select 'a','http://xxx.com','1' union all
select 'b','http://xxx.com/1','0' union all
select 'c','http://xxx.com/3','0'