SQL选择匹配 [英] SQL Select Matches

查看:52
本文介绍了SQL选择匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,我想匹配这两个表.我尝试使用Excel,但由于Excel工作表中的行数超过200.000,因此无法正常运行.我得到了excel的答案-通过SQL Server在excel中查找序列号数据库- 我正在寻找将这两个表与MSSMS匹配的答案. 问候

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

FirstTable

Material SerialNumber 
MTR5100 1 
MTR5100 2 
MTR4100 3 
MTR4100 4

可检查表

Material SerialNumber
MTR5100 1 
MTR5100 2 
MTR6100 3 
MTR4100 5


我想将FirstTable与CheckTable匹配
*如果存在SerialNumber,并且其Material与FirstTable中的Material名称相同,它将在检查字段中写入"ok"
*如果存在SerialNumber,但其Material与FirstTable中的Material名称不同,则宏将在数据库中写入与我们正在寻找的序列号相关的Material Name
*如果序列号"不存在,它将写"nok"以检查字段


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

使用sql查询,我想得到这个结果;

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

推荐答案

听起来像您要找的是普通的SQL.我认为您应该花30分钟的时间,自己学习一些SQL ...其实并不难.查看这些教程:

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教程

最后,您需要导入excel文件.通常,这涉及将它们另存为逗号分隔的文本文件,然后将其导入到您选择的数据库中.

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.

这篇关于SQL选择匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆