日期:2014-05-17 浏览次数:20425 次
select a.CustInfoName,
(select count(b.id) from oa_ContactInfo as b where b.custid=a.id group by custid) as 交往次数,
(select top 1 Contacts from oa_ContactInfo as b where b.custid=a.id order by addtime desc) as 最新交往内容 //有的获取的不对,不是最后一次交往的信息
from oa_CustomerInfo as a
select *
from oa_CustomerInfo a inner join
(select custid,Contacts,ROW_NUMBER() OVER(PARTITION BY custid order by addtime desc)rn,
COUNT(id) OVER(PARTITION BY custid )ct from oa_ContactInfo)b
on b.custid=a.id where rn=1