0
T1:
ID   
100
101
102

T2:
ID     OWNDATE   
100    1.1.2001
100    3.1.2001
101    2.1.2001
102    4.1.2001

我想要类似的东西,select * from T1 但是按 T2 表中的 MAX 自己的日期列排序?

结果将是

102
100
101

这可能吗?谢谢

对不起

4

1 回答 1

3

只需在 ID 上将两个表连接在一起,然后订购OWNDATE

SELECT T1.* 
FROM T1 
INNER JOIN T2 on T1.[ID] = T2.[ID]
ORDER BY T2.OWNDATE

更新:

SELECT T1.* FROM T1
INNER JOIN (
    SELECT [ID], MAX(OWNDATE) AS OWNDATE
    FROM T2
    GROUP BY [ID]
) T2 ON T1.[ID] = T2.[ID]
ORDER BY OWNDATE DESC
于 2012-07-19T14:19:48.133 回答