我有一个包含 PrimaryCustomerID 和 PositionCode 列的表。 PriamryCustomerID 包含客户银行投资组合 ID,PositionCode 包含银行产品代码(WSO 和 PB)。
我必须选择具有 WSO PositionCode 的客户,但不得有 PB 代码。 如果选择PositionCode为WSO的客户,则排除PB客户,但这并不意味着客户没有PB。
请帮忙。 谢谢
最佳答案
这将列出位置代码 = 'WSO' 且不存在位置代码 = 'PB' 的行的所有客户。应该可以在 sql-server 和 mySQL 上工作。
SELECT a.primaryCustomerID, a.PositionCode
from table a
where a.positionCode = 'WSO'
and not exists (select 1 from table b where b.primaryCustomerID = a.primaryCustomerID and b.positionCode = 'PB')
关于mysql - 选择 SQL 数据库中仅具有一种产品的客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477770/