SQL 选择匹配
我有两张桌子,我想匹配这两张桌子。我尝试使用 Excel,但效果不佳,因为 Excel 工作表有超过 200.000 行。我得到了 excel 的答案 -通过 SQL Server 在 excel 中查找序列号数据库- 我正在寻找将这两个表与 MSSMS 匹配的答案。 问候,
FirstTable
Material SerialNumber
MTR5100 1
MTR5100 2
MTR4100 3
MTR4100 4
Checktable
Material SerialNumber
MTR5100 1
MTR5100 2
MTR6100 3
MTR4100 5
我想将 FirstTable 与 CheckTable 匹配
*如果 SerialNumber 存在且其材质与 FirstTable 中的材质名称相同,则会写入“ok”来检查字段
*如果 SerialNumber 存在,但其材质与 FirstTable 中的材质名称不同,则宏会将数据库中的材质名称写入数据库中,以引用我们要查找的序列
*如果Serial不存在,它会写“nok”来检查字段
用sql查询,我想得到这个结果;
Material SerialNumber Check
MTR5100 1 ok
MTR5100 2 ok
MTR4100 3 MTR6100
MTR7100 4 nok
I have two tables, I would like to match these two tables. I tried with Excel but I did not work well because Excel sheet has more than 200.000 rows. I got answer for excel -Lookup serial numbers in excel through SQL Server database-
I am looking for an answer for matching these two tables with MSSMS.
Regards,
FirstTable
Material SerialNumber
MTR5100 1
MTR5100 2
MTR4100 3
MTR4100 4
Checktable
Material SerialNumber
MTR5100 1
MTR5100 2
MTR6100 3
MTR4100 5
I would like to match FirstTable with CheckTable
*if SerialNumber exist and its Material is the same as the material name in the FirstTable, it will write "ok" to check field
*if SerialNumber exist but its Material is different from the material name in FirstTable, macro will write the material name in database refer to serial that we are looking for
*if Serial does not exist, it will write "nok" to check field
With sql query, I would like to get this result;
Material SerialNumber Check
MTR5100 1 ok
MTR5100 2 ok
MTR4100 3 MTR6100
MTR7100 4 nok
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在寻找的是相当简单的 SQL。我认为你应该花 30 分钟,自己学习一些 SQL...这真的没那么难。查看这些教程:
SQL 教程
最后,您需要导入 Excel 文件。通常,这涉及将它们保存为逗号分隔的文本文件,然后将它们导入到您选择的数据库中。
It sounds like what your looking for is fairly trivial SQL. I think you should take 30 minutes, and learn some SQL yourself... It's really not that hard. Check these tutorials out:
SQL Tutorials
Lastly, you'll need to import your excel files. Often, this involves saving them as comma separated text files, and then importing those into the database of your choice.