![](/img/trans.png)
[英]Compare the values within the same column against other columns in SQL Server
[英]Compare the values in the same column and with other column values in sql server
我的表中有3列ID
, serial_no
, priority_no
。
可能如下所示
--------------------
ID | Ser_No | pri_NO
--------------------
1 | 123 | 215
1 | 123 | 280
2 | 215 | 215
3 | 123 | 360
4 | 111 | 111
-------------------
看桌子
我们有相同ser_no
为ID 1和3,并且我们具有用于ID 1和2相同pri_no
为ID = 1,我们有Pri_No
为215和215相同为Ser_No
在ID = 2
反之亦然,一条记录的ser_no将在另一条记录的Pri_No
以上条件,我们称其为Family
现在我需要的输出是(不是家庭记录)
--------
ID
--------
4
--------
select id from table a
where not exists
(select * from table where (a.Ser_No = Ser_No or a.pri_NO = pri_NO) and id!=a.id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.