大家好,我有一个小断言让我有点难过。我有一个如下表。(这是我的真实表的示例。我用它来解释,因为原始表有敏感数据。)
CREATE TABLE TEST01(
TUID VARCHAR2(50),
FUND VARCHAR2(50),
ORG VARCHAR2(50));
Insert into TEST01 (TUID,FUND,ORG) values ('9102416AB','1XXXXX','6XXXXX');
Insert into TEST01 (TUID,FUND,ORG) values ('9102416CC','100000','67130');
Insert into TEST01 (TUID,FUND,ORG) values ('955542224','1500XX','67150');
Insert into TEST01 (TUID,FUND,ORG) values ('915522211','1000XX','67XXX');
Insert into TEST01 (TUID,FUND,ORG) values ('566653456','xxxxxx','xxxxx');
Insert into TEST01 (TUID,FUND,ORG) values ('9148859fff','1XXXXXX','X6XXX');
插入后的表数据
"TUID" "FUND" "ORG"
"9102416AB" "1XXXXX" "6XXXXX"
"9102416CC" "100000" "67130"
"955542224" "1500XX" "67150"
"915522211" "1000XX" "67XXX"
"566653456" "xxxxxx" "xxxxx"
"9148859fff" "1XXXXXX" "X6XXX"
“X”是通配符元素*(我继承了这个,我无法更改表格格式)*我想进行如下查询
select tuid from test01 where fund= '100000' and org= '67130'
但是我真正喜欢做的是检索任何包含这些段的记录,包括“X”
in other words the expected output here would be
"TUID" "FUND" "ORG"
"9102416AB" "1XXXXX" "6XXXXX"
"9102416CC" "100000" "67130"
"915522211" "1000XX" "67XXX"
"566653456" "xxxxxx" "xxxxx"
我已经开始编写一个庞大的 sql 语句,其中包含 12 个类似的语句,因为我必须比较组织并以各种可能的方式资助。这就是我要去的地方。但我想知道是否有更好的方法。
select * from test02
where fund = '100000' and org = '67130'
or fund like '1%' and org like '6%'
or fund like '1%' and org like '67%'
or fund like '1%' and org like '671%'
or fund like '1%' and org like '6713%'
or fund like '1%' and org like '67130'
or fund like '10%' and org like '6%'...etc
/*seems like there should be a better way..*/
谁能帮我想出这个sql语句...
顺便注意一下
"9148859fff" "1XXXXXX" "X6XXX"
被排除在预期结果之外,因为 org 中的第二个数字是“6”,我正在寻找任何看起来像“67130”的东西