select a.dealid, a.dealname, a.dealdetails, b.dcid, b.commenttime, b.commentperson, b.commentfrom deals a, dealcomments bwhere b.dealid = a.dealid and b.commenttime = (select max(x.commenttime) from dealcomments x where x.dealid = b.dealid)
编辑:我没有足够接近地阅读初始问题,也没有注意到视图中需要所有DEALS行。以下是我的修改后的答案:
select a.dealid, a.dealname, a.dealdetails, b.dcid, b.commenttime, b.commentperson, b.commentfrom deals a left outer join (select x.dcid, x.dealid, x.commenttime, x.commentperson, x.commentfrom dealcomments xwhere x.commenttime = (select max(x1.commenttime) from dealcomments x1 where x1.dealid = x.dealid)) bon (a.dealid = b.dealid)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)