这现在正在起作用-我想问一下,我将如何获得一列 请问我们该服务的最后日期是几天前?
select full_name, event_name, actual_date,
row_number() over(partition by ev.full_name order by ev.actual_date DESC) as row_num --<<--<<--
from event_expanded_view ev
where
ev.full_name is not Null and ev.category_code in('OTHER_ACT', 'CONTACTS', 'PEOPLEPLANS', 'PEOPLETESTS', 'PERSONREQ')
)
select full_name, event_name, actual_date from cte_ul_ev where row_num = 1
答案 0 :(得分:0)
像这样尝试...
;WITH
cte_ul_ev AS (
SELECT DISTINCT
ev.full_name,
ev.event_name,
ev.actual_date,
row_num = ROW_NUMBER() OVER (PARTITION BY ev.full_name ORDER BY ev.actual_date DESC) --<<--<<--
FROM
dbo.event_expanded_view ev
WHERE
ev.full_name IS NOT NULL
AND ev.category_code IN ('OTHER_ACT', 'CONTACTS', 'PEOPLEPLANS', 'PEOPLETESTS', 'PERSONREQ')
)
SELECT
ue.full_name,
ue.event_name,
ue.actual_date
FROM
cte_ul_ev ue
WHERE
ue.row_num = 1;