【发布时间】:2021-06-09 20:23:43
【问题描述】:
所以我有一个客户数据库,其中包含 Customer_Account_ID、Phone_No 和 Alt_Phone_No。现在 Alt_Phone_No 可以有一个数字值,也可以有空白。我想要一个数据格式如下的输出:
假设客户 ID 是 12345678 电话号码是 4021234444 和 4022221234 我们应该在电子表格上有两行:
Customer ID Phone number
12345678 4021234444
12345678 4022221234
如果 Alt_Phone_No 中没有值,则不应有任何第二个条目,即在这种情况下只需要客户 ID 和电话号码。
我大致想到的如下:
SELECT Customer_Account_ID, Phone_No FROM Table_A a,
(SELECT Customer_Account_ID, Phone_No FROM Table_A, Table_B
where Table_A.Cust_ID = Table_B.Cust_ID
and condition = ' ' /*filter needed as per requirements*/
UNION ALL
SELECT Customer_Account_ID, Alt_Phone_No FROM Table_A, Table_B
where Table_A.Cust_ID = Table_B.Cust_ID
and condition = ' ' /*filter needed as per requirements*/ ) b
where a.Cust_ID = b.Cust_ID
and rownum < 1000 /*need rownum for testing sample data as the original data is too large*/
order by a.Cust_Id
我认为查询不正确。非常感谢所有的建议和意见。
【问题讨论】: