0

我有 2 个表..我正在将状态历史记录移动到一个表中并将其显示在另一个表中..第二个表获取最近的状态并将其显示在网页中输出

像这样我需要..但我越来越

需要的输出

我需要更新的记录以及空状态记录。我的查询是:

with ctr as
(
 select en.status update,ed.no,row_number()
 over (partition by ed.no order by en.update descending) as [RN], 
 ed.[conference date],ed.conference name,ed.region,ed.inquiry,
 ed.attended by,ed.doctor name,ed.hospital,ed.contact no,ed.email, ed.adds,
 CONVERT(VAR CHAR(10),en.[update], 103) as update,ed.closed,
 CONVERT(VAR CHAR(10),ed.[closing date],103) as closing date,
 ed.closed by, ed.revenue, ed.approve status, ed.Enid from inquiries_details ed
 inner join
 inquiries en on ed.Enid = en.Enid
 inner join
 staff_details SD on ed.region = SD.state
 where region = 'Maharashtra' 
)
 select * from ctr where RN = 1 

谁能帮我

4

1 回答 1

0

您可以尝试使用以下查询,可能是内部联接的问题.. 将其更改为左联接

with ctr as
(
 select en.status update,ed.no,row_number()
 over (partition by ed.no order by en.update descending) as [RN], 
 ed.[conference date],ed.conference name,ed.region,ed.inquiry,
 ed.attended by,ed.doctor name,ed.hospital,ed.contact no,ed.email, ed.adds,
 CONVERT(VAR CHAR(10),en.[update], 103) as update,ed.closed,
 CONVERT(VAR CHAR(10),ed.[closing date],103) as closing date,
 ed.closed by, ed.revenue, ed.approve status, ed.Enid from inquiries_details ed
 left join
 inquiries en on ed.Enid = en.Enid
 left join
 staff_details SD on ed.region = SD.state
 where region = 'Maharashtra' 
)
 select * from ctr where RN = 1 
于 2013-03-26T06:18:15.710 回答