gpt4 book ai didi

MySql 列匹配 3 个连续数字

转载 作者:行者123 更新时间:2023-11-30 00:45:35 25 4
gpt4 key购买 nike

我有两个表,假设名为 AllComputers 和 MfgComputers。 Allcomputers 中有趣的列是 Brand_Name、Model_Name 和 Model_Number。 Mfgcomputers 中有趣的列是 Product_Name。

我可以使用以下查询来显示 Brand_Name 为 HP 且 Model_Name 或 Model_Number 与 Product_Name 完全匹配的所有行。

select * from AllComputers,MfgComputers where AllComputers.Brand_Name='HP' AND AllComputers.Model_Number=MfgComputers.Product_Name OR AllComputers.Model_Name=MfgComputers.Product_Name;

我想匹配 Brand_Name 为 HP 的位置,但仅当两个匹配中至少包含三个连续数字时,才使用 LIKE 或 REGEX 来匹配 Model_Number 和 Model_Name 与 Product_Name 匹配的所有行。

因此,如果我的 Model_Name 为 HP Pavilion 500 All-in-One PC,Product_Name 为 HP 500 All-in-One PC,我只想返回两者都为 500 的匹配项,而不是所有包含“All合一电脑。

我尝试用 LIKE 替换上述查询中的最后两个 = 符号,但仍然只匹配完全匹配的内容,因为我不知道如何为整个列添加通配符。

我知道如果只匹配一个特定模型,我可以使用通配符,例如: 从 AllComputers 中选择 *,其中 Model_Number LIKE '%500%';或者 从 AllComputers 中选择 *,其中 Model_Number REGEXP '500';

但是,我想知道是否可以在所有至少有 3 个连续数字的模型匹配的列之间执行此操作。

最佳答案

MySQL 中的 REGEXP 有数字通配符,因此请尝试 REGEXP '.*[0-9][0-9][0-9].*'

.* 相当于 LIKE '%',因此实际上将 3 个数字夹在两个 % 之间。

关于MySql 列匹配 3 个连续数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21388229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com