![](/img/trans.png)
[英]How do you update a specific table column based on the value of another column of the same table?
[英]How to filter a table based on a specific column value of another column?
你好我这里有一张桌子
---------------------
ID | PARTY | Name.Id
---------------------
1 | IND | 12
2 | IND | 13
3 | CUST | 14
4 | CUST | 15
5 | CUST | 16
6 | IND | 17
---------------------
我想返回整个表,但过滤“Name.Id”列中值为 15 和 16 的“CUST”
结果应该是这样的
---------------------
ID | PARTY | Name.Id
---------------------
1 | IND | 12
2 | IND | 13
3 | CUST | 14
4 | IND | 17
---------------------
我尝试在“Name.Id”上使用where
语句,但它只返回那些值为 15 和 16 的行。
整个表,但在“Name.Id”列中过滤“CUST”,其值为 15 和 16
听起来您想要一个 where 子句,例如:
WHERE NOT (party = 'CUST' and name.id IN(15,16))
但是 CUST 从您的示例数据中似乎是多余的,即您可以将其简化为WHERE name.id NOT IN (15,16)
你可以试一试吗?
select *
from t
where (PARTY, Name.Id) not in (
select 'CUST', 15
union
select 'CUST', 16
)
select *
from t
where Party not in
(select Party from t
where Party="CUST"
and (Name.Id=15 or Name=16));
我想我在这里找到了解决方案
select *
from t
where Party <> 'CUST'
or (Party = 'CUST'
and Name.Id = 14))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.