简体   繁体   English

MySQL 上的 LIKE function 没有找到相似的词

[英]LIKE function on MySQL not picking up similar words

I am currently using db-fiddle.com to practice my SQL code.我目前正在使用 db-fiddle.com 来练习我的 SQL 代码。

I have two tables.我有两张桌子。

'Customers': '顾客':

Customers_id客户ID PracticeName实践名称 Location地点 PracticeType练习类型 Subref子参考
1 1 Hermitage Vets冬宫兽医 Essex埃塞克斯 Farm农场 P030022 P030022
2 2 West End Vets西区兽医 Edinburgh爱丁堡 Companion伴侣 P030023 P030023

'Samples': “样品”:

Samples_id Samples_id Subref子参考 SampleType样品类型 det检测 FAM FAM VIC维克 Gel_result凝胶结果
1 1 P030022_1 P030022_1 SWAB拭子 MHYPCR多聚酶链反应 38.72 38.72 35.00 35.00 null null
2 2 P030022_2 P030022_2 SWAB拭子 MHYPCR多聚酶链反应 34.23 34.23 30.05 30.05 null null
3 3 P030022_3 P030022_3 SWAB拭子 MHYPCR多聚酶链反应 34.00 34.00 29.99 29.99 null null
4 4 P030022_4 P030022_4 SWAB拭子 MHYPCR多聚酶链反应 30.00 30.00 37.10 37.10 null null

(There are more subref samples and more columns in Samples but I didn't want to clutter the page.) (Samples 中有更多 subref 示例和更多列,但我不想弄乱页面。)

There can be multiple samples as part of one subref that is why I made them two tables with the underscore to define results per sample.可以有多个样本作为一个子引用的一部分,这就是为什么我用下划线将它们制作成两个表来定义每个样本的结果。

I want to be able to see all the samples that are part of the Subref next to PracticeName.我希望能够看到属于 PracticeName 旁边的 Subref 的所有示例。 So the end result is the Samples table but with the PracticeName column attached.所以最终结果是 Samples 表,但附加了 PracticeName 列。

Sorry if this is not the best way to format things but I am a very new beginner.抱歉,如果这不是格式化事物的最佳方式,但我是一个非常新的初学者。

I tried both these codes, which apparently executed but nothing showed up in the results:我尝试了这两个代码,这些代码显然已执行,但结果中没有显示任何内容:

SELECT * FROM Customers, Samples WHERE Customers.Subref LIKE (Samples.Subref + '%');

SELECT * FROM Customers, Samples WHERE Customers.Subref LIKE concat (Samples.Subref, '%');

I have also tried creating another table to do many-to-many queries but again it executed with no results:我还尝试创建另一个表来执行多对多查询,但它再次执行但没有结果:

  Customers_id INT UNSIGNED NOT NULL
  , Samples_id SMALLINT UNSIGNED NOT NULL
  , PRIMARY KEY pk_Customers2Samples (Customers_id, Samples_id)
);
WHERE Customers.Subref like 'Samples.Subref%';

I am not sure what I am doing wrong.我不确定我做错了什么。

Any advice appreciated, please be nice.任何建议表示赞赏,请善待。

Looking to yourdata sample.. due the repsence of _n at the end yous houdl use the inverse (match for string from customers + % like the string in samples)查看您的数据示例..由于最后 _n 的表示,您应该使用逆向(匹配来自客户的字符串 + % 像示例中的字符串)

SELECT * 
FROM Customers
INNER JOIN Samples ON  Samples.Subref LIKE concat (Customers.Subref, '%')

the string for Sample in your data containg more chats respect the value in customers then can't macth.. the opposite should work您的数据中 Sample 的字符串包含更多聊天尊重客户的价值然后无法计算.. 相反应该有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM