sql server 2008 - SQL group by on one column with other columns selected -
i have function returns results below, how can remove duplicate rows? group how build function? , use inner joins on 'h' fields.
select action.holiday_id, action.id, --h.holiday_name, --h.date_start, --h.date_end, (select count(distinct action.holiday_id) action) 'count' action --inner join holiday_ref h on action.holiday_id=h.holiday_id action.delete_date null --group action.holiday_id holiday_id id count 31 5 3 31 6 3 31 8 3 332 7 1
so like:
31 3 332 1
this should work.
with cte ( select holiday_id, id, holiday_name, date_start, date_end, row_number() on (partition holiday_id order holiday_id) [index] action ) select holiday_id, id, holiday_name, date_start, date_end, (select count(*) action holiday_id = cte.holiday_id , delete_date null) [count] cte [index] = 1
edit: checks delete_date
well
Comments
Post a Comment