SQL:如何比较两个单词的各个部分?
我有带有 ID 列的表 1 和带有 ID 号列的表 2。 ID 格式例如为“aac557z”。我想按编号比较这些 ID。 表 1:
和表 2:
我想从 table1 中选择列 ID 中单词为“567”的行。数字可能不同。 也许有人有想法? 我正在使用 MS Access 2010。 提前致谢。
I have table1 with ID column and table2 with ID number column. ID format for example is "aac557z". I want to compare those ID's by the piece where is number.
Table1:
And Table2:
I want to select rows from table1 where the piece of the word is "567" in column ID. Numbers may be different.
Maybe someone has an idea?
I'm using MS Access 2010.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 ID 的数字部分始终位于相同位置且长度相同,则可以使用
MID
函数获取数字部分进行比较。在大桌子上它不会很快。以下是语法链接:http://office.microsoft.com/access-help/mid-function-HA001228881.aspx" microsoft.com/en-us/access-help/mid-function-HA001228881.aspx
如果您要经常进行此比较,最好在表中添加另一个字段并用插入表时 ID 的数字部分。然后使用该字段进行比较,您的查询应该会更快。
If the numeric part of the ID is always in the same place and the same length you can use the
MID
function to get the number part for the comparison. It's won't be very fast on large tables.Here's a link to the syntax: http://office.microsoft.com/en-us/access-help/mid-function-HA001228881.aspx
If you are going to do this comparison often it might be better to add another field to your table and populate it with the numeric part of the ID when it is inserted in to the table. Then using that field for your comparison your query should be faster.
您可以使用用户定义的函数从 Id 中提取数字部分,然后其余部分就相当简单了。
这是一个完成这项工作的函数:
然后进行比较,如下所示:
如果表非常大,那么这将是一个昂贵的查询!
You could use a user-defined function to extract the number part from the Id and then the rest is fairly trivial.
Here's a function to do the job:
And then to compare, something like this:
If the tables are very large, then this is going to be an expensive query!