基本的T-sql问题

时间:2011-04-07 07:12:47

标签: sql-server tsql

我有一张邀请表。像这样;

Email           CreateDate
a@gmail.com     2011-03-04 10:10:46.273 
b@gmail.com     2011-03-10 12:06:26.673
c@gmail.com     2011-03-20 12:06:26.673
c@gmail.com     2011-03-10 12:06:26.673 

如何归还?

a@gmail.com     2011-03-04 10:10:46.273    1
b@gmail.com     2011-03-10 12:06:26.673    1
c@gmail.com     2011-03-20 12:06:26.673    2

3 个答案:

答案 0 :(得分:3)

 SELECT Email, Max(CreateDate), Count(CreateDaate) FROM YourTable Group By Email.

答案 1 :(得分:0)

select Email, max(CreateDate), count(*)
from Invitation
group by Email

答案 2 :(得分:0)

您也可以使用以下复杂的。因此,您可以学习partition by子句。

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