<?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 Re: correlated subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/correlated-subsearch/m-p/76995#M19486</link>
    <description>&lt;P&gt;I'm no master of correlated subqueries, but this might be it. &lt;/P&gt;

&lt;P&gt;I'm reading your SQL as saying "find me most recent entries in T for each combination of type and user, and give me the type and the sum of the count field from those entries.  Then group these by type and show me just the rows earlier than 24 hours ago. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... latest=-24h | eventstats max(_time) as maxTime by user type | where _time=maxTime | stats sum(count) as count by type&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If my interpretation is wrong (as it very well may be) can you write it out in english?&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2013 22:02:05 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2013-03-27T22:02:05Z</dc:date>
    <item>
      <title>correlated subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/correlated-subsearch/m-p/76994#M19485</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I'm looking for a way to do an equivalent of a SQL correlated subquery in Splunk.  [I did look at &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.2/SearchReference/SQLtoSplunk" target="_blank"&gt;Splunk for SQL users&lt;/A&gt; - it doesn't have an answer].&lt;/P&gt;

&lt;P&gt;I have events of the form: _time user=A type=B count=N.  I'd like to express the following SQL in Splunk:&lt;BR /&gt;
Select type, sum(count) from T &lt;BR /&gt;
where _time=(Select max(_time) from T as T' where T'.type=T.type and T'.user=T.user) &lt;BR /&gt;
group by type&lt;BR /&gt;
where T._time + 24h &amp;lt; current_time()&lt;/P&gt;

&lt;P&gt;Is there a way to do this?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:37:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/correlated-subsearch/m-p/76994#M19485</guid>
      <dc:creator>composite</dc:creator>
      <dc:date>2020-09-28T13:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: correlated subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/correlated-subsearch/m-p/76995#M19486</link>
      <description>&lt;P&gt;I'm no master of correlated subqueries, but this might be it. &lt;/P&gt;

&lt;P&gt;I'm reading your SQL as saying "find me most recent entries in T for each combination of type and user, and give me the type and the sum of the count field from those entries.  Then group these by type and show me just the rows earlier than 24 hours ago. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;... latest=-24h | eventstats max(_time) as maxTime by user type | where _time=maxTime | stats sum(count) as count by type&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If my interpretation is wrong (as it very well may be) can you write it out in english?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2013 22:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/correlated-subsearch/m-p/76995#M19486</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2013-03-27T22:02:05Z</dc:date>
    </item>
  </channel>
</rss>

