我有以下查询: + D4 U6 P& `- A( e) C8 }INSERT into @TEST (col1,staffnumber,rn)SELECT starttime as col1,staffnumber,ROW_NUMBER() OVER (PARTITION BY StaffNumber ORDER BY STARTTIME DESC) AS rn FROM @TempTable2 t2UNION SELECT eventdate as col1,staffnumber,ROW_NUMBER() OVER (PARTITION BY StaffNumber ORDER BY EVENTDATE DESC) AS rn FROM @TempTable1 t1但是,显然,这给了我以下值: n; h( k% q2 Z: s3 |2 s6 pCOL | staffnumber | rn10/02/2014 10:29:24 110/02/2014 09:08:19:00:19:19 1110/02/2014:00:00:2014:00:00:29 而且我需要它来显示:/ f' R& P& M# Y
COL | staffnumber | rn10/02/2014 10:29:24 110/02/2014 09:08:19:00:19:19 110/02/201410:00:00:2014 10:00:20::200:20:2014 我可以通过执行以下操作来做到这一点: ) \! M% P8 K) w. Q) SINSERT into @TEST1 (col1,staffnumber,rn)SELECT convert(time,col1),staffnumber,ROW_NUMBER() OVER (PARTITION BY StaffNumber ORDER BY convert(time,COL1) DESC) AS rnFROM @TEST但必须有一种更简单、更有效的方法。有什么想法吗?8 D% t6 d% A [" I
0 T; N! ] h) H 解决方案: