, as shown in the figure above for sending data, the following data for the reply, now want to send time is the most similar distance query response time, the calculation of the two time lag, for example, the sender sent the first message for the 2020-10-20 17:17:43. 760, the result of the need to get the 2020-10-20 17:24:43. 770, the two time is the most similar, trouble know bosses provide a train of thought, thank you!
CodePudding user response:
SELECT * FROM TABLE A
CROSS the APPLY
(SELECT TOP 1 MSGTIME FROM TABLE WHERE A.R OOMID=ROOMID AND CHARINDEX (A.F ROM, TOLIST) & gt; 0 AND CHARINDEX (FROM, A.T OLIST) & gt; 0 AND MSGTIME> Arjun SGTIME ORDER BY MSGTIME) AS B