sql - Remove duplicate date in postgres -
my need unique value after concatenating 2 string values. below query. strings concatenated duplicated values coming. doing wrong?
select ievent.event_type_id evt_type_id, ievent.event_value evt_value, ievent.event_date evt_dt, ievent.company, ievent.entity_key, row_number() on (order ievent.event_date desc) row_num ( select we.executive_id, we.event_type_id, sum(we.event_value) event_value, array_to_string(array_agg(distinct (coalesce(mc.aka_co_name,mc.company_name))),',') company, we.event_date, null entity_key wealth_event we, master_company mc mc.company_id = we.company_id , mc.is_active = 'y' , (we.event_value > 1 , we.event_value < 5000000000 , we.event_value not null , we.event_type_id in (1, 3, 4, 5)) , we.event_date <= trunc(current_date) , we.event_date > trunc(current_date) - 180 group we.event_date, we.executive_id, we.event_type_id union select we.executive_id, we.event_type_id, sum(we.event_value) event_value, array_to_string(array_agg(distinct mc.aka_co_name),',') company, we.event_date, we.entity_key wealth_event we, master_company mc mc.company_id = we.company_id , mc.is_active = 'y' , (we.event_type_id in (6, 7, 8, 9, 10, 14, 16, 19, 20, 21, 24, 23)) , we.event_date <= trunc(current_date) , we.event_date > trunc(current_date) - 180 group we.event_date, we.executive_id, we.event_type_id, we.entity_key ) ievent, executive exec ievent.executive_id = exec.executive_id , exec.is_active = 'y' , exec.executive_id = 73685 order row_num
main problem of query using aggregate functions (sum , array_agg) @ subquery without group .
maybe need :
select event_type_id , sum(we.event_value) event_value, evt_dt, null entity_key, array_to_string( distinct ( array_agg ( coalesce(mc.aka_co_name, mc.company_name)) ), ',' ) company wealth_event we, master_company mc mc.company_id = we.company_id , mc.is_active='y' group event_type_id , evt_dt
Comments
Post a Comment