如何将指定SQL查询转换为Fetch XML?sql2fetchxml工具转换失败
将目标SQL转换为FetchXML的实现方案
你的SQL需求是找出关联了恰好2个电话记录的机会,返回机会的负责人ID和对应的电话数量,并按电话数量排序。对应的FetchXML实现如下:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="opportunity"> <!-- 取出机会的负责人ID --> <attribute name="ownerid" /> <!-- 关联电话实体,使用inner join匹配关联关系 --> <link-entity name="phonecall" from="vsg_loan" to="opportunityid" alias="b" link-type="inner" aggregate="true"> <!-- 统计每个机会对应的电话数量,别名为call_count --> <attribute name="vsg_loan" alias="call_count" aggregate="count" /> <!-- 筛选出电话数量等于2的分组 --> <filter type="having"> <condition attribute="vsg_loan" operator="eq" value="2" aggregate="count" /> </filter> <!-- 按vsg_loan(即机会ID)分组 --> <groupby> <attribute name="vsg_loan" /> </groupby> </link-entity> <!-- 按电话数量排序 --> <order attribute="call_count" alias="b" descending="false" /> </entity> </fetch>
关键说明:
- 主实体为
opportunity,通过link-entity关联phonecall实体,关联字段为phonecall.vsg_loan与opportunity.opportunityid - 在关联实体上启用聚合统计,通过
groupby按机会ID分组,再用having条件筛选出电话数量等于2的记录 - 最终返回机会的负责人ID和统计得到的电话数量,并按数量排序
内容的提问来源于stack exchange,提问作者Arvind Gurumurthi
相关产品推荐
相关产品推荐

