SQL语句记录:
一对多关系字段的合并以及截取
select STUFF ((SELECT ',' + b.Name
FROM dbo.contract AS a left join dbo.Company b on a.create_company_id=b.CompanyId
WHERE (plan_contract_id = @plan_contract_id) for xml path('')), 1, 1, '')
根据字段business_id 进行分组,在分组内根据time进行排序
select ROW_NUMBER() over ( PARTITION BY business_id order by time asc)