我有两个表Security和CallPut。security (table1)包含security_id和maturity_date (非NULL值),Callput(table2)包含security_id和odate (它们是包含日期时间格式值的非NULL值)我想从security (表1)中选择所有行,但在maturity_date中,我想要Odate列中的值,而不是maturity_date,其中Security id存在于CallPut(table2)中并与security表匹配
Security_id|Maturity_date
abcd 25Jan2020
bcde 25jan2021 Callput(tabble2)
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)提前感谢
发布于 2013-03-17 03:28:49
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附注:我刚注意到这是一个Oracle问题,我的代码是针对MS SQL Server的
编辑:已针对Oracle语法进行更正。
发布于 2013-03-17 03:38:29
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-17 03:28:40
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内容丰富的文档中了解有关连接的更多信息
https://stackoverflow.com/questions/15453671
复制相似问题