22,207
社区成员
发帖
与我相关
我的任务
分享
drop table if exists AAA;
drop table if exists SSS;
create table AAA(matchId int,serialNo varchar(100),Amount int);
insert into AAA
select 705,'4097513',1 union all
select 4157,'5048222',1 union all
select 403,'4356888',1;
create table SSS(MatchId int,openSerialsNums varchar(1000));
insert into SSS
select 705,'4097513,4680864,6030953' union all
select 785,'4097513,4680864,6030953' union all
select 531,'4097513,4680864,6030953' union all
select 385,'4097513,4680864,6030953' union all
select 917,'5048222,5210240,5380259' union all
select 785,'5048222,5210240,5380259' union all
select 4157,'5048222,5210240,5380259' union all
select 385,'5048222,5210240,5380259';
select case when AAA.matchId is not NULL then N'是' else '' end as Amout, sss.* from sss
left join AAA on SSS.MatchId=AAA.MatchId and INSTR(','+AAA.serialNo+',',','+SSS.openSerialsNums+',')>0;
SELECT CASE WHEN SSS.MatchId = AAA.matchId THEN '是'
ELSE ''
END ,
*
FROM SSS
LEFT JOIN AAA ON instr(CONCAT(,CONCAT(',' ,SSS.openSerialsNums) , ','),CONCAT(CONCAT(',', AAA.serialNo),',')) > 0;
SELECT (CASE WHEN SSS.MatchId = AAA.matchId THEN '是'
ELSE ''
END )as Amount,
SSS.*
FROM SSS
LEFT JOIN AAA ON instr(CONCAT(CONCAT(',' ,SSS.openSeriesNums) , ','),CONCAT(CONCAT(',', AAA.serilaNo),',')) > 0;
SELECT CASE WHEN SSS.MatchId = AAA.matchId THEN '是'
ELSE ''
END ,
*
FROM SSS
LEFT JOIN AAA ON CHARINDEX(',' + AAA.serialNo + ',',
',' + SSS.openSerialsNums + ',') > 0;
;with AAA(matchId,serialNo,Amount)AS(
select 705,'4097513',1 union all
select 4157,'5048222',1 union all
select 403,'4356888',1
),SSS(MatchId,openSerialsNums)AS(
select 705,'4097513,4680864,6030953' union all
select 785,'4097513,4680864,6030953' union all
select 531,'4097513,4680864,6030953' union all
select 385,'4097513,4680864,6030953' union all
select 917,'5048222,5210240,5380259' union all
select 785,'5048222,5210240,5380259' union all
select 4157,'5048222,5210240,5380259' union all
select 385,'5048222,5210240,5380259'
)
select case when AAA.matchId is not NULL then N'是' else '' end as Amout, sss.* from sss
left join AAA on SSS.MatchId=AAA.MatchId and charindex(','+AAA.serialNo+',',','+SSS.openSerialsNums+',')>0
Amout MatchId openSerialsNums
1 是 705 4097513,4680864,6030953
2 785 4097513,4680864,6030953
3 531 4097513,4680864,6030953
4 385 4097513,4680864,6030953
5 917 5048222,5210240,5380259
6 785 5048222,5210240,5380259
7 是 4157 5048222,5210240,5380259
8 385 5048222,5210240,5380259