基于First datetime的唯一ID

时间:2014-10-29 15:48:31

标签: sql database datetime unique

我试图找出如何运行SQL查询以仅显示具有最早日期时间戳(FBPOINTSDTS)的唯一用户(CUSTOMER_ID)。我已经研究过使用DISTINCT,但是还没能使它工作。

这是我的示例表:

ID              |CUSTOMER_ID     |REFERENCE_ID    |FBPOINTSDTS
VA00001000001336|CU00001000001173|RC00001000265536|10/28/2014 18:27
VA00001000000221|CU00001000001440|RC00001000249871|06/20/2014 14:10
VA00001000000249|CU00001000001440|RC00001000250058|06/21/2014 13:23
VA00001000001332|CU00001000001472|RC00001000265527|10/28/2014 17:01
VA00002000000434|CU00001000001637|RC00002000428796|10/28/2014 15:57
VA00001000000145|CU00001000001866|RC00001000248169|06/07/2014 12:04
VA00001000000343|CU00001000001866|RC00001000251616|07/07/2014 10:35

任何建议都表示赞赏!

1 个答案:

答案 0 :(得分:0)

select customer_id, min(FBPOINTSDTS) from [your table] group by customer_id;

此查询将显示唯一的CUSTOMER_ID及其最小FBPOINTSDTS。