sql查找一列中包含另一张表截取部分字段的数据

数据库查询优化与数据匹配
该博客主要涉及数据库查询优化,通过SQL语句示例展示了如何使用LIKE运算符和SUBSTRING函数进行数据匹配。讨论了如何在特定时间范围内筛选数据,并强调了Fixture_no列的前11个字符在连接不同表中的关键作用。

截取d表中Fixture_no列前11个字段,连接b表fixture_no列:
d.Fixture_no like concat(’%’,b.fixture_no,’%’)
or
b.fixture_no= substring(d.Fixture_no,1,11)

select a.part_num, a.mc_code, a.pm_no, a.NC_For, a.part_rev, b.RF, b.part_no, b.orientation, b.rev, b.fixture_no, c.fixture_no, c.Location, d.Fixture_no, d.Status, d.Origin, d.Trans_Date 
from [dbo].[partmachtime] as a,
[dbo].[fms_where_use] as b,
[dbo].[fms_store] as c,
[dbo].[fms_Trans_Record] as d
where a.part_num = b.part_no and a.NC_For = b.orientation and a.part_rev = b.rev and a.pm_no = d.Origin and a.pm_no= c.Location and b.RF = 'M'and Trans_Date between '2021-12-06 00:00:00.000' and '2021-12-12 23:59:59.000'
and d.Fixture_no like concat('%',b.fixture_no,'%') 
select distinct b.part_no,d.Fixture_no  
from [dbo].[fms_Trans_Record] d,
[dbo].[fms_where_use] b
where b.fixture_no= SUBSTRING(d.Fixture_no,1,11) 
and d.Trans_Date between '2021-12-06 00:00:00.000' and '2021-12-12 23:59:59.000'AND d.Workshop='LMC'
and ((d.Origin like 'M%' and d.Destination like 'M%') or (d.Origin not like 'M%' and d.Destination not like 'M%'))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值