<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Group By functionality of da.cursors sql_clause in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567169#M18729</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I must be doing something wrong. I am trying to use the Group By functionality of the new da.SearchCursor, but keep getting the error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: Underlying DBMS error [Microsoft SQL Server Native Client 11.0: Column 'demo.test.PRCL_AL_WEST.OBJECTID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.] [demo.test.PRCL_AL_WEST][STATE_ID = 88181]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't understand this as I am not including OBJECTID in my field list, and it wouldn't make sense to include it in my Group By.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I am trying to solve is; I have a bunch of feature classes in different datasets that are identical except that they have different projections (don't ask, I can't change this part), so I get the list of feature classes in the fcs variable by using the da.Walk functionality (really cool), filtered with the fnmatch module, and am trying to get record counts to track progress by date (removing time portion), user and create method code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know there are other tools like Statistics that can be used, but I am mostly just experimenting with the new 10.1 functionality, and would like to get this working, as it has lots of potential.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the code below conn is a connection to a sqlite3 in-memory database and c is the cursor for it, I am inserting the individual feature class results into the sqlite table, then doing an aggregate to get the total counts from there, later in the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;fieldList = ["COUNT(*) as GroupCount", "CONVERT(DATE, CRET_TS) as CRET_TS", "GISF_CRET_METH_CD", "BWCreator"]
sqlclaus = [None, "GROUP BY CONVERT(DATE, CRET_TS),GISF_CRET_METH_CD,BWCreator"]
#Gather the counts from the individual feature classes
for fc in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in arcpy.da.SearchCursor(fc, fieldList, sql_clause=sqlclaus):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #insert the individual feature class counts into the sqlite table
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vals = [fc]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vals.extend(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.execute("INSERT INTO rslt VALUES(?,?,?,?,?)", vals)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.commit()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help you can provide is much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 17 Feb 2013 10:53:47 GMT</pubDate>
    <dc:creator>PaulBrandt</dc:creator>
    <dc:date>2013-02-17T10:53:47Z</dc:date>
    <item>
      <title>Group By functionality of da.cursors sql_clause</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567169#M18729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I must be doing something wrong. I am trying to use the Group By functionality of the new da.SearchCursor, but keep getting the error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: Underlying DBMS error [Microsoft SQL Server Native Client 11.0: Column 'demo.test.PRCL_AL_WEST.OBJECTID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.] [demo.test.PRCL_AL_WEST][STATE_ID = 88181]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't understand this as I am not including OBJECTID in my field list, and it wouldn't make sense to include it in my Group By.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I am trying to solve is; I have a bunch of feature classes in different datasets that are identical except that they have different projections (don't ask, I can't change this part), so I get the list of feature classes in the fcs variable by using the da.Walk functionality (really cool), filtered with the fnmatch module, and am trying to get record counts to track progress by date (removing time portion), user and create method code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know there are other tools like Statistics that can be used, but I am mostly just experimenting with the new 10.1 functionality, and would like to get this working, as it has lots of potential.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the code below conn is a connection to a sqlite3 in-memory database and c is the cursor for it, I am inserting the individual feature class results into the sqlite table, then doing an aggregate to get the total counts from there, later in the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;fieldList = ["COUNT(*) as GroupCount", "CONVERT(DATE, CRET_TS) as CRET_TS", "GISF_CRET_METH_CD", "BWCreator"]
sqlclaus = [None, "GROUP BY CONVERT(DATE, CRET_TS),GISF_CRET_METH_CD,BWCreator"]
#Gather the counts from the individual feature classes
for fc in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in arcpy.da.SearchCursor(fc, fieldList, sql_clause=sqlclaus):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #insert the individual feature class counts into the sqlite table
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vals = [fc]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vals.extend(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.execute("INSERT INTO rslt VALUES(?,?,?,?,?)", vals)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.commit()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help you can provide is much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Feb 2013 10:53:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567169#M18729</guid>
      <dc:creator>PaulBrandt</dc:creator>
      <dc:date>2013-02-17T10:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Group By functionality of da.cursors sql_clause</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567170#M18730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I believe that the call to arcpy.da.searchCursor will always include 'OBJECTID' in the output results, and so you'll need to include that in your aggregation function. So after your main 'GROUP BY' statement, append 'OBJECTID', in your case:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;sqlclaus = [None, "GROUP BY CONVERT(DATE, CRET_TS),GISF_CRET_METH_CD,BWCreator,OBJECTID"]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This won't affect the results as the column only contains unique results, but should allow your above query to run (provided this was the sole issue).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2013 19:07:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567170#M18730</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2013-06-06T19:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Group By functionality of da.cursors sql_clause</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567171#M18731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm with this problem too, but I can't aggregate the "OBJECTID" in clause sql (group by), because impact in results. You have another solution?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SQL:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;select avg(velocity), max(velocity), team, date(date_team) from &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;table where (date(date_team) between '2013-06-27' and '2013-07-20') and team= 3260 group by team, date(date_team)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 17:55:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567171#M18731</guid>
      <dc:creator>WesleyAntal2</dc:creator>
      <dc:date>2014-06-10T17:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Group By functionality of da.cursors sql_clause</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567172#M18732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is a general issue when using SQL aggregate functions, but basically, just include the additional column you're grouping on in the results. So, something like MIN(OBJECTID) in the WHERE clause of the SQL statement.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jun 2014 04:47:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567172#M18732</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2014-06-11T04:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Group By functionality of da.cursors sql_clause</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567173#M18733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I try, but too return error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I solved with other way. Used the arcpy.ArcSDESQLExecute with my clause SQL (select avg(velocity), max(velocity), team, date(date_team)::varchar(10) from table where (date(date_team) between '27/06/2013' and '20/07/2013') AND team = 3260 group by team, date(date_team)::varchar(10)) and after with "for" inserted in my temporary table.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jun 2014 12:25:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/group-by-functionality-of-da-cursors-sql-clause/m-p/567173#M18733</guid>
      <dc:creator>WesleyAntal2</dc:creator>
      <dc:date>2014-06-11T12:25:27Z</dc:date>
    </item>
  </channel>
</rss>

