查询为每个关联人选择1个潜在客户。
如何按Lead_ID + MAX(person.Created_Timestamp)分组
select
top 100 lead.lead_id,person.first_name,person.last_name,person.gender,person.modified_ts
from lead
left join person on person.lead_id=lead.lead_id
left join person_email on person_email.person_id=person.person_id
left join person_address on person_address.person_id=person.person_id
left join address_location on person_address.address_location_id=address_location.address_location_id
where address_location.state_code = 'QL'
答案 0 :(得分:0)
select
lead.lead_id, MAX(person.Created_Timestamp)
from lead
left join person on person.lead_id=lead.lead_id
left join person_email on person_email.person_id=person.person_id
left join person_address on person_address.person_id=person.person_id
left join address_location on person_address.address_location_id=address_location.address_location_id
where address_location.state_code = 'QL'
GROUP BY lead.lead_id