我有一个由ClientID,ActionDate,Action和Result组成的表。
我需要选择在给定日期范围内仅具有特定操作/结果组合的不同客户端。
举例说明:
由于
答案 0 :(得分:2)
1
select ClientID from
(
select
ClientID,
Action,
Result,
row_number() over (partition by ClientID order by ActionDate desc) as num
from ClientActions
) T -- the latest 5 action/result
where rnum <= 5
group by ClientID
having MAX(case when Action='Call' and Result = 'NoAnswer' then 0 else 1 end) = 0
2
select ClientID
from ClientActions
where DATEDIFF(DAY, ActionDate, GETDATE()) <= 30
group by ClientID
having MAX(case when Action='Call' and Result = 'NoAnswer' then 0 else 1 end) = 0