【发布时间】:2020-05-16 16:35:58
【问题描述】:
我有一个名为 Customer 的表,其架构如下。
Create Table Customer(id Number,customer_type varchar(20),customer_status char(1),account_number varchar(20));
Insert into Customer(id,customer_type,customer_status,account_number)values(123,'RETAIL','A','32456798');
Insert into Customer(id,customer_type,customer_status,account_number)values(123,'RETAIL','I','92456798');
Insert into Customer(id,customer_type,customer_status,account_number)values(123,'RETAIL','P','22456798');
Insert into Customer(id,customer_type,customer_status,account_number)values(123,'PERSONAL','A','42456798');
Insert into Customer(id,customer_type,customer_status,account_number)values(123,'PERSONAL','I','52456798');
Insert into Customer(id,customer_type,customer_status,account_number)values(123,'PERSONAL','P','62456798');
Insert into Customer(id,customer_type,customer_status,account_number)values(243,'PERSONAL','A','02456798');
commit;
我正在尝试获取客户状态处于活动状态的 Id。Customer_type 可以是两种类型 RETAIL 或 PERSONAL。如果 id 有任何活动的 retils,我只想返回 Retail true帐户其他虚假, 与 个人 相同 我尝试了以下查询,但无法返回 id
select REATIL,PERSONAL from (select case when customer_status = 'A' then 'Y' else 'N' end as REATIL from Customer where customer_status='A' and customer_type='RETAIL')
,(select id, case when customer_status = 'A' then 'Y' else 'N' end as PERSONAL from Customer where customer_status='A' and customer_type='PERSONAL');
预期输出:
|---------------------|------------------|----------------|
| id | Retail | Personal |
|---------------------|------------------|----------------|
| 123 | Y | Y |
|---------------------|------------------|----------------|
| 243 | N | Y |
|---------------------|------------------|----------------|
我们将不胜感激。
【问题讨论】:
-
更新您的问题,添加适当的数据样本和预期结果作为表格文本(不是图像)
-
更新了问题。
标签: sql oracle oracle11g oracle10g