2013-12-20 106 views
0

查詢爲每個相關聯的人選擇1個潛在顧客。爲多個輔助加入記錄選擇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
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