0

我有两张表 Security 和 CallPut。安全性(table1)包含security_id和mature_date(非noll值)和CallPut(table2),它具有security_id和Odate(它们是包含日期时间格式值的非空值)我想从security(表1)中选择所有行但在成熟日期我想要来自 odate 列的值而不是成熟日期,其中安全 id 存在于 Callput(table2) 中并与安全表匹配

例如安全(table1)

Security_id|Maturity_date
abcd        25Jan2020
bcde        25jan2021 

调用(表2)

Security_id|Odate
abcd        25Jan2015 

所需输出

Security_id|Maturity_date
abcd        25Jan2015 (since here id is there in callput it takes odate)
bcde        25jan2021 (since here id is not there in callput it takes maturity date)

我用oracle sql 请帮忙。提前致谢

4

3 回答 3

1
select 
    s.Security_id,
    NVL(c.Odate, s.Maturity_date) Maturity_date
from 
    security s left join callput c 
    on (c.security_id = s.security_id);
于 2013-03-16T19:38:28.550 回答
0
select s.* from security as s left join callput as c on (c.security_id = s.security_id);

未经测试,但您想使用联接。您可以在http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm了解有关 Oracle 大量文档的更多信息

于 2013-03-16T19:28:39.837 回答
0
select s.Security_id, nvl(c.odate, s.Maturity_date) as Maturity_date
from Security s
left join
Callput c
on
s.Security_id = c.Security_id

ps 刚刚注意到这是一个 Oracle 问题,我的代码适用于 MS SQL Server
编辑:针对 Oracle 语法进行了更正。

于 2013-03-16T19:28:49.083 回答