oracle中下面3表的关联查询,查询出满足条件的,contactsummary 表中的第一条数据! 10
selectto_char(tc.createtime,'yyyy/mm/ddhh24:mi:ss')fromcontactsummarytcs,contactcommt...
select to_char(tc.createtime, 'yyyy/mm/dd hh24:mi:ss')
from contactsummary tcs,
contactcomm tcc,
contact tc
where rownum = 1
and trunc(tc.dtcreatetime) <= ADD_MONTHS(trunc(sysdate), -12)
and tcc.lid = tc.lid
and tcs.lcontactid = tcc.lcontactid;
上面的这个写法,我总感觉有点错误!有大侠能帮个忙吗?
字段dtcreatetime 应该是createtime 写错了! 展开
from contactsummary tcs,
contactcomm tcc,
contact tc
where rownum = 1
and trunc(tc.dtcreatetime) <= ADD_MONTHS(trunc(sysdate), -12)
and tcc.lid = tc.lid
and tcs.lcontactid = tcc.lcontactid;
上面的这个写法,我总感觉有点错误!有大侠能帮个忙吗?
字段dtcreatetime 应该是createtime 写错了! 展开
1个回答
展开全部
你要查的是contactsummary 表中的第一条数据,那只能是from 这个表,不能from一个关联
而且 rownum只能是对结果的第一行,必须用一个子查询取出符合条件的contactsummary
select *
from(
select * from contactsummary tcs
where
exists( select 1 from contactcomm tcc, contact tc
where trunc(tc.dtcreatetime) <= ADD_MONTHS(trunc(sysdate), -12)
and tcc.lid = tc.lid
and tcs.lcontactid = tcc.lcontactid;
)
where rownum = 1
而且 rownum只能是对结果的第一行,必须用一个子查询取出符合条件的contactsummary
select *
from(
select * from contactsummary tcs
where
exists( select 1 from contactcomm tcc, contact tc
where trunc(tc.dtcreatetime) <= ADD_MONTHS(trunc(sysdate), -12)
and tcc.lid = tc.lid
and tcs.lcontactid = tcc.lcontactid;
)
where rownum = 1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询