2011-04-07 48 views
0

我有一個邀請表。喜歡這個;基本的T-sql問題

Email   CreateDate 
[email protected]  2011-03-04 10:10:46.273 
[email protected]  2011-03-10 12:06:26.673 
[email protected]  2011-03-20 12:06:26.673 
[email protected]  2011-03-10 12:06:26.673 

如何返回?

[email protected]  2011-03-04 10:10:46.273 1 
[email protected]  2011-03-10 12:06:26.673 1 
[email protected]  2011-03-20 12:06:26.673 2 
+0

這可以由許多人在這裏回答。你寫了什麼SQL? – shahkalpesh 2011-04-07 07:14:43

+1

確實是「基本」。你有什麼嘗試? – RichardTheKiwi 2011-04-07 07:23:35

回答

3
SELECT Email, Max(CreateDate), Count(CreateDaate) FROM YourTable Group By Email. 
0
select Email, max(CreateDate), count(*) 
from Invitation 
group by Email 
0

您可以使用下面的複雜其一也。因此你可以通過子句學習分區。

select a.email,max(Date),max(a.rn) from (select email,date,ROW_NUMBER() over(partition by email order by email)rn from #a)a group by email