SQL Server 除外
这是我所处的情况。我有一个包含人员信息的表。 其中有些是从其他系统导入的,有些是手动导入的。 我想做的是将所有人都拉进来,但如果有一条手动输入的记录和一条导入的记录,我只想选择导入的记录(因为它可能是最新的)。
这是我到目前为止所拥有的,但它似乎不起作用(它只返回手动输入的记录):
SELECT --fields go here
FROM
(
SELECT PERSON_UID, instype
FROM AdmitsInterfaceTable
WHERE instype='M' --Manually entered people
EXCEPT
SELECT PERSON_UID, instype
FROM AdmitsInterfaceTable
WHERE instype='I' --Imported people
) P,
AdmitsInterfaceTable A
WHERE
P.PERSON_UID=A.PERSON_UID
AND P.instype=A.instype
我有一种感觉这不起作用,因为内部查询也拉入了 instype 列,但我可以想不出更好的方法来做到这一点。 有什么建议吗?
Here's the situation I'm in. I have a table containing peoples' information. Some of them are imported from another system while some are imported manually. What I would like to do is pull everyone in, but if there is a record entered manually and a record that was imported, I want to select only the imported one (since it is likely more up to date).
Here is what I have so far, but it doesn't seem to work (it only returns the manually entered records):
SELECT --fields go here
FROM
(
SELECT PERSON_UID, instype
FROM AdmitsInterfaceTable
WHERE instype='M' --Manually entered people
EXCEPT
SELECT PERSON_UID, instype
FROM AdmitsInterfaceTable
WHERE instype='I' --Imported people
) P,
AdmitsInterfaceTable A
WHERE
P.PERSON_UID=A.PERSON_UID
AND P.instype=A.instype
I have a feeling this isn't working because of the inner query also pulling in the instype column, but I can't think of any better ways to do this. Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试:
you could try: