本文介绍了需要使用CTE从2个表中链接和选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 需要从2个表中选择数据。 表格为1. COMPLAINT(EMPNO,EMPNAME) 2. UTILITY(EMPNO,EMPNAME) 查询应排除 COMPLAINT UTILITY 中的记录/ b> 字段 EMPNO 是主要参考 选择TOP 1 EMPNO, 来自投诉的EMPNAME EMPNO集团,EMPNAME订购EMPNO DESC UNION 选择EMPNO,EMPNAME来自UTILIY 和UTILITY.EMPNO 不在投诉中 请协助 谢谢 我是什么尝试过: 查看我在CTE中的早期代码。 还检查了互联网。但是我从未在CTE中找到任何'NOT IN' 的例子。 任何参考资料都会非常欢迎need to pick data from 2 tables.The tables are 1. COMPLAINT (EMPNO,EMPNAME) 2. UTILITY (EMPNO,EMPNAME) The query should exclude records in UTILITY which are in COMPLAINT The field EMPNO is the main reference SELECT TOP 1 EMPNO , EMPNAME FROM COMPLAINT GROUP BY EMPNO,EMPNAME ORDER BY EMPNO DESC UNION SELECT EMPNO,EMPNAME FROM UTILIY AND UTILITY.EMPNO NOT IN COMPLAINT Please assist ThanksWhat I have tried:Checked my earlier codes in CTE . Have also checked the Internet. However I never found any example with the 'NOT IN'IN CTE.Any referencesites will be most welcomed推荐答案 在不知道你的表格以及你想要归还的确切内容的情况下,你无法准确地告诉你该怎么做。但请看一下: SQL连接的可视化表示 [ ^ ] - 您可能想要其中一个三个EXCLUDING JOIN,它给出了示例代码。Without knowing your tables and exactly what you want to return it's not possible to tell you exactly what to do. But have a look here: Visual Representation of SQL Joins[^] - you probably want one of the three EXCLUDING JOINs, and it gives sample code. 这篇关于需要使用CTE从2个表中链接和选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-02 04:04