我有两个有date_updated
列的表。
TableA
就像下面
con_id date_updated type
--------------------------------------------
123 19/06/2018 2
123 15/06/2018 1
123 01/05/2018 3
101 06/04/2018 1
101 05/03/2018 2
我TableB
也有同样的结构
con_id date_updated type
--------------------------------------------
123 15/05/2018 2
123 01/05/2018 1
101 07/06/2018 1
结果表应包含最近日期的数据
con_id date_updated type
--------------------------------------------
123 19/06/2018 2
101 07/06/2018 1
这里的date_updated
列是datetime
sql server 的数据类型。我通过使用group by
和选择最大值来尝试这个date_updated
。但我无法在select
语句中包含列类型。当我使用输入时group by
,结果不正确,因为类型也被分组。我该如何查询这个。请帮忙