2011-04-07 47 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