zoukankan      html  css  js  c++  java
  • (转)Support for COUNT(DISTINCT) in Fetch XML queries

    Support for COUNT(DISTINCT) in Fetch XML queries

    10 Mar 2009 12:19 PM
    • Comments 3

    We have made a couple of enhancements to the aggregate query feature of Fetch XML. These updates have shipped for version 4.0 as part of UR2 and for version 3.0 as documented in KB Article 960079. So far we only supported the count aggregate function which essentially did a count(*) on the base table of the entity.

    We have enhanced this functionality to add a new aggregate operation countcolumn which now performs the SQL count operation for a given column. It also support the distinct keyword which only counts unique columns. If the distinct keyword is not specified with a countcolumn aggregate, its value defaults to false.

    Here is a table that summarizes the Fetch aggregate types and its equivalent SQL translation:

    CRM Fetch XML

    SQL

    <attribute name='address1_city' aggregate='count' alias='citycount' />

    SELECT COUNT(*) AS 'citycount' FROM Account

    <attribute name='address1_city' aggregate='countcolumn' alias='citycount' />

    SELECT COUNT(address1_city) AS 'citycount' FROM Account

    <attribute name='address1_city' aggregate='countcolumn' alias='citycount' distinct='true' />

    SELECT COUNT(DISTINCT address1_city) AS 'citycount' FROM Account

                                                         Key: Existing Feature, New Feature

    Here are a couple of examples for using these features:

    Query to return a count of all Accounts which have a county specified in their address.

       1: Query to return a count of all Accounts which have a county specified in their address.
       2: <fetch aggregate='true'>
       3:     <entity name='account'>
       4:         <attribute name='address1_county' aggregate='countcolumn' alias='countyAccounts' />
       5:     </entity>
       6: </fetch>

    Query to return a count of states in which we have an account. This uses the distinct keyword which counts a state only once.

       1: <fetch aggregate='true'>
       2:     <entity name='account'>
       3:         <attribute name='address1_stateorprovince' aggregate='countcolumn' alias='countStates' distinct='true' />
       4:     </entity>
       5: </fetch>

    Thanks

    Noor Merchant

  • 相关阅读:
    jquery组件WebUploader文件上传用法详解
    asp.net Forms身份验证详解
    FormsAuthentication使用指南
    对于新手用c#中的delegate(委托)和event(事件)
    Union All/Union/Intersect操作
    DALFactory出现"未能加载文件或程序集“DAL”或它的某一个依赖项。系统找不到指定的文件”的解决方案 .
    C#多线程编程实例 线程与窗体交互
    FormsAuthentication使用指南
    asp.net Forms身份验证详解
    chrome浏览器调试JS代码
  • 原文地址:https://www.cnblogs.com/janmson/p/1773051.html
Copyright © 2011-2022 走看看