引用同一行中不同列的SQL Case语句

引用同一行中不同列的SQL Case语句,sql,Sql,我试图写一个select语句,确定客户是否在过去3个月内多次注册,同时仍提供我工作的表中的所有数据(以下示例) 我想象案例查询应该是这样的,但我不知道如何引用我希望结果填充的行: case when name in (select name from table1 where count(name from this row) > 1 and count(email from this row) > 1 and (date from this row) >= getdate()

我试图写一个select语句,确定客户是否在过去3个月内多次注册,同时仍提供我工作的表中的所有数据(以下示例)

我想象案例查询应该是这样的,但我不知道如何引用我希望结果填充的行:

case when name in
(select name
from table1
where count(name from this row) > 1
and count(email from this row) > 1
and (date from this row) >= getdate()-120
end
表有3列:

name, email, date

有什么帮助吗?谢谢。

如果您的数据库是
SQL Server 2005
或更高版本,那么您可以将查询编写为:

create table table1 (name varchar(20), email varchar(50), date datetime);
insert into table1 values ('Name1','email@abc.com',getdate()-30);
insert into table1 values ('Name1','email@abc.com',getdate()-60);
insert into table1 values ('Name1','email@abc.com',getdate());
insert into table1 values ('Name2','email2@abc.com',getdate()-20);
insert into table1 values ('Name3','email3@abc.com',getdate());
insert into table1 values ('Name4','email4@abc.com',getdate()-120);

with CTE as
(
select  
row_number() over (partition by [name],[email] order by [name] asc) as rownum,
[name],
[email],
[date]
from table1
where [date] > = GETDATE() - 120
)   
select * from CTE    
where rownum > = 3

请提供一些样本数据和预期输出。