我在表中有一列,其中包含多个标识符值。表中的另一列标识值所关联的 ID 类型。表中还有一个键 ID 列(这是另一个 ID 值)。我想要完成的是识别 where 语句中的键 ID 列表,并在此基础上返回 2 个不同的 ID 值作为它们自己的列(基于 Id_type 作为标题)以及键 ID。见下文
Table: external_ids
| id_type | identifier | key_id |
| program.id | 123456 | abcde |
| partner.id | 5432 | abcde |
| product.id | 6KWt1Qo04O2M | abcde |
| aps | EP013836200004 | abcde |
| program.id | 789012 | defghi |
| partner.id | 9876 | defghi |
| product.id | 9bb72eb42a93f | defghi |
| aps | EP012795410004 | defghi |
这是我正在使用的查询(我知道它不起作用):
select distinct
identifier, identifier, key_id
from external_ids
where key_id in ('abcde','defghi')
and id_type = (select identifier from external_ids
where id_type in ('aps','product.id')
我希望的输出是:
| aps | product.id | key_id |
| EP013836200004 | 6KWt1Qo04O2M | abcde |
| EP012795410004 | 9bb72eb42a93f | defghi |