sql - 如何在 SQL 中过滤来自 2 个不同表的数据,但另一个表几乎没有要忽略的字符串?
问题描述
例如:
- 一张表有 Apple、Google、Facebook 等帐户名称。
- 其他表的帐户名称为 2-apple、3-google、4-facebook。
我需要根据帐户名称组合这两个表,但希望查询忽略另一个表中的前 2 个字符串值 = 粗体值(2-
苹果、3-
谷歌、4-
Facebook)。
解决方案
记住小写以避免比较问题
with x as (
select 'Google' as mark from dual union all
select 'Facebook' as mark from dual
),
y as (
select '2-apple' as other from dual union all
select '3-google' as other from dual union all
select '4-facebook' as other from dual
)
select x.mark, y.other
from x inner join y
on ( lower(x.mark) = lower(substr(y.other,3)) );
结果
SQL> with x as (
select 'Google' as mark from dual union all
select 'Facebook' as mark from dual
),
y as (
select '2-apple' as other from dual union all
select '3-google' as other from dual union all
select '4-facebook' as other from dual
)
select x.mark, y.other
from x inner join y
on ( lower(x.mark) = lower(substr(y.other,3)) );
MARK OTHER
-------- ----------
Google 3-google
Facebook 4-facebook
推荐阅读
- javascript - 如何使用 CryptoJS AES 两次使用 AES 加密
- python - 从变量sqlite python3 sqlalchemy中获取列名
- amazon-web-services - AWS Fargate 容器身份验证配置
- android - 使用较低的 Android API 捕获 WebView (chrome) 崩溃
- php - Str_replace not replacing completely
- asp.net - 如何使用来自 web api 的 POST 重定向到另一个站点?
- python - 计算文件中的总字数?
- google-apps-script - 谷歌脚本花费太多时间。错误服务超时
- apache - 从 https://example.com 重定向到 https://www.example.com
- c++ - 如何仅使用寄存器在 arduino due (sam3x8e) 上的 c++ 中进行外部中断?