【发布时间】:2012-08-31 09:10:49
【问题描述】:
我想加入两个表“客户”和“激活”。以下是它们的结构:
CUSTOMER Activation
------------ -------------
Id Name EntityId Date_Created Type
1 A 1 2012 EMAIL
2 B 2 2011 SMS
3 C
现在,我想在 customer.Id = Activation.EntityId 上加入这两个表。但是,我希望我的最终表结构是这样的:
Id Name Date_Email Date_SMS
1 A 2012 NULL
2 B NULL 2011
基本上,Date_Email 和 Date_SMS 列都来自 Activation.Date_Created 列。如果 Activation.Type 是 EMAIL,我将最终结果中的 Date_Email 设置为 Date_created 并将 Date_SMS 设置为 null。如果 Activation.type 是 SMS,我会采用另一种方式。
我现在拥有的是这样的:
SELECT Customer.Id, Name, Date_Created AS Date_EMail, DATE_Created AS Date_SMS
from Customer
inner join Activation ON Customer.Id = Activation.EntityId;
现在,我需要根据 Activation.Type 列创建一个 If-else 条件。我对此很陌生,我无法通过谷歌搜索来解决这个问题。顺便说一句,我正在使用 Oracle XE 数据库
有人可以帮我解决这个问题吗?谢谢
【问题讨论】:
-
Activation中每种类型和 EntityId 组合是否只有一行? -
@lc。是的,EntityId 是一个外键,引用客户表中的 Id。对不起,我应该提到这一点
-
@hari,你确定这是一个好的设计吗?我个人不鼓励这样做。
-
@Yossarian 你能告诉我为什么吗?