<?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: head and sort a column inside a table generated by `stats` in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554452#M157383</link>
    <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="country	zipcode
US	AAAAAA
CA	BBB BBB
US	AAACCC
PE	AAAAAA
AR	AAAAAA
CA	BBB BBB
UK	AAACCC
BE	AAAAAA
US	AAAAAA
NL	BBB BBB
US	AAACCC
DE	AAAAAA
SA	AAAAAA
FR	BBB BBB
ES	AAACCC
NL	AAAAAA
US	AAAAAA
CA	BBB BBB
US	AAACCC
US	AAAAAA
US	AAAAAA
CA	BBB BBB
UK	AAACCC
BE	AAAAAA
US	AAAAAA
NL	BBB BBB
US	AAACCC
DE	AAAAAA
SA	AAAAAA
FR	BBB BBB
ES	AAACCC
BR	AAAAAA"
| multikv forceheader=1
| table country zipcode



| eventstats count by country
| sort -count country
| streamstats dc(country) as countryrank
| where countryrank&amp;lt;=10
| stats count values(countryrank) as countryrank by country zipcode
| sort country -count
| streamstats dc(zipcode) as rank by country
| where rank&amp;lt;=10
| sort countryrank rank&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 04 Jun 2021 09:29:13 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2021-06-04T09:29:13Z</dc:date>
    <item>
      <title>head and sort a column inside a table generated by `stats`</title>
      <link>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554171#M157323</link>
      <description>&lt;P&gt;`base search&amp;nbsp;&lt;SPAN&gt;| stats values(zipcode), count(zipcode) as c by country | sort -c | head 10`&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;which gives me most appeared 10 countries in the base search.&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I still need to count how many times each zipcode shows and get head 10 most zipcode under each country.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone can figure out how to write this?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 02:13:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554171#M157323</guid>
      <dc:creator>RmDok</dc:creator>
      <dc:date>2021-06-03T02:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: head and sort a column inside a table generated by `stats`</title>
      <link>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554191#M157327</link>
      <description>&lt;LI-CODE lang="markup"&gt;base search 
| stats count by zipcode country 
| sort 0 country -num(count)
| streamstats count as rank by country
| where rank &amp;lt;= 10&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 03 Jun 2021 05:10:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554191#M157327</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-03T05:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: head and sort a column inside a table generated by `stats`</title>
      <link>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554356#M157351</link>
      <description>&lt;P&gt;Thank you, but that's not what I mean.&amp;nbsp;&lt;/P&gt;&lt;P&gt;base search will give&lt;/P&gt;&lt;TABLE border="1" width="64.0176605839842%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;country&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;zipcode&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;US&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;AAAAAA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;CA&lt;/TD&gt;&lt;TD height="24px"&gt;BBB BBB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;US&lt;/TD&gt;&lt;TD&gt;AAACCC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;US&lt;/TD&gt;&lt;TD&gt;AAAAAA&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to find top 10 countries appear most in the country column&lt;/P&gt;&lt;P&gt;based on that, in each country, zipcode also need to be counted and sorted to get most appeard 10 zipcode as well&lt;/P&gt;&lt;P&gt;the expected output for above table is&lt;/P&gt;&lt;TABLE border="1" width="56.20689523449687%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="24px"&gt;country&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;zipcode&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="24px"&gt;US&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;AAAAAA&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;AAACCC&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="24px"&gt;CA&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;BBB BBB&lt;/TD&gt;&lt;TD width="25%" height="24px"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 19:31:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554356#M157351</guid>
      <dc:creator>RmDok</dc:creator>
      <dc:date>2021-06-03T19:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: head and sort a column inside a table generated by `stats`</title>
      <link>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554452#M157383</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="country	zipcode
US	AAAAAA
CA	BBB BBB
US	AAACCC
PE	AAAAAA
AR	AAAAAA
CA	BBB BBB
UK	AAACCC
BE	AAAAAA
US	AAAAAA
NL	BBB BBB
US	AAACCC
DE	AAAAAA
SA	AAAAAA
FR	BBB BBB
ES	AAACCC
NL	AAAAAA
US	AAAAAA
CA	BBB BBB
US	AAACCC
US	AAAAAA
US	AAAAAA
CA	BBB BBB
UK	AAACCC
BE	AAAAAA
US	AAAAAA
NL	BBB BBB
US	AAACCC
DE	AAAAAA
SA	AAAAAA
FR	BBB BBB
ES	AAACCC
BR	AAAAAA"
| multikv forceheader=1
| table country zipcode



| eventstats count by country
| sort -count country
| streamstats dc(country) as countryrank
| where countryrank&amp;lt;=10
| stats count values(countryrank) as countryrank by country zipcode
| sort country -count
| streamstats dc(zipcode) as rank by country
| where rank&amp;lt;=10
| sort countryrank rank&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Jun 2021 09:29:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/head-and-sort-a-column-inside-a-table-generated-by-stats/m-p/554452#M157383</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-04T09:29:13Z</dc:date>
    </item>
  </channel>
</rss>

