<?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: How do you translate SQL into Splunk? in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456503#M56201</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/146667"&gt;@mnikhil7692&lt;/a&gt; hardcoding was only to generate sample data as per your question as we will not have same data as your system. Please provide some sample events (mock/anonymize any sensitive information).&lt;/P&gt;

&lt;P&gt;Unless we know what your event looks like and what are your fields it will not be easy for us to assist, however, based on your query provided &lt;STRONG&gt;try the following and confirm&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="MyIndex" sourcetype="MySourceType" source="MySource" 
| eval _time=strptime(creation_date_time,"%m/%d/%Y")
| timechart count(eval(FLAG=="O")) as Outbound count(eval(FLAG=="I")) as Inbound dc(provider_name) as Providers
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR May be the following if you do not need Time as epoch time and your existing creation_date_time is in &lt;CODE&gt;MM/DD/YYYY&lt;/CODE&gt; format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="MyIndex" sourcetype="MySourceType" source="MySource" 
| chart count(eval(FLAG=="O")) as Outbound count(eval(FLAG=="I")) as Inbound dc(provider_name) as Providers by creation_date_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the run anywhere example based on cooked up data as per my understanding of your data. Each event has creation_date_time in MM/DD/YYYY format. FLAG O and I denote Outbound and Inbound respectively and provider_name can repeat, where you want unique provider count. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;PS: Intention of run anywhere search is to demo the required output. Instead of commands from | makeresults till | KV, you will use your main search using index="MyIndex" sourcetype="MySourceType" source="MySource", as mentioned above.&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval data="CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| KV
| eval _time=strptime(CREATION_DATE_TIME,"%m/%d/%Y")
| timechart count(eval(FLAG=="O")) as Outbound count(eval(FLAG=="I")) as Inbound dc(provider_name) as Providers
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 21:52:33 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-29T21:52:33Z</dc:date>
    <item>
      <title>How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456500#M56198</link>
      <description>&lt;P&gt;Hi there, &lt;/P&gt;

&lt;H2&gt;Per the attached picture, i just put this data in Excel and got this chart out. However, i was not able to get this into Splunk.  Visualization does not show me anything.&lt;IMG src="https://community.splunk.com/storage/temp/255329-sql2dshbrd.jpg" alt="alt text" /&gt;Obviously, i am missing something. Please advise.&lt;/H2&gt;

&lt;HR /&gt;

&lt;P&gt;Here's the query I'm running, which generates the same results :&lt;/P&gt;

&lt;P&gt;SELECT &lt;BR /&gt;
    TRUNC(CREATION_DATE_TIME),&lt;BR /&gt;
    COUNT(1) TOTAL_PROCESSES, &lt;BR /&gt;
    COUNT( distinct PROVIDER_name ) DISTINCT_PROVIDERS, &lt;BR /&gt;
    SUM(CASE WHEN FLAG = 'O' THEN 1 END ) OUTGOING,&lt;BR /&gt;
    SUM(CASE WHEN FLAG = 'I' THEN 1 END ) INCOMING,&lt;BR /&gt;
FROM&lt;BR /&gt;
    &lt;MY_TABLE&gt; &lt;BR /&gt;
GROUP BY TRUNC(CREATION_DATE_TIME) &lt;/MY_TABLE&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;HR /&gt;

&lt;P&gt;here's what i am running in Splunk :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="MyIndex" sourcetype="MySourceType" source="MySource" 
| eval x_out=if((FLAG=="O"),1,0), x_in=if((FLAG=="I"),1,0) 
| convert ctime(creation_date_time) as cdt timeformat=%m/%d/%y 
| timechart span=7d dc(provider_name) by cdt
| stats sum(x_out) as Outbound sum(x_in) as Inbound dc(provider_name) as Providers
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:51:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456500#M56198</guid>
      <dc:creator>mnikhil7692</dc:creator>
      <dc:date>2020-09-29T21:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456501#M56199</link>
      <description>&lt;P&gt;@mnikhil7692 what is the source of your data? Are you indexing spreadsheet data or any other data to Splunk or is it coming from CSV which has been uploaded to Splunk lookup file.&lt;/P&gt;

&lt;P&gt;If it is indexed to Splunk what do the events look like? Do you have fields already extracted?&lt;/P&gt;

&lt;P&gt;If the data shows up exactly the way you have displayed in your table, and there is one event per day, just the &lt;CODE&gt;table&lt;/CODE&gt; command should work.&lt;/P&gt;

&lt;P&gt;Following is a run anywhere example which uses command from &lt;CODE&gt;| makeresult&lt;/CODE&gt; till &lt;CODE&gt;| KV&lt;/CODE&gt; to generate some sample events as per data. Then uses table to plot the table. You can change visualization to Line Chart in Splunk to see the result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="CREATION_DATE_TIME=10/24/2018,TOTAL_PROCESS=96,DISTINCT_PROVIDERS=21,OUTGOING=38,INCOMING=58;CREATION_DATE_TIME=10/25/2018,TOTAL_PROCESS=96,DISTINCT_PROVIDERS=21,OUTGOING=37,INCOMING=59;CREATION_DATE_TIME=10/26/2018,TOTAL_PROCESS=95,DISTINCT_PROVIDERS=21,OUTGOING=37,INCOMING=58;"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| KV
| table CREATION_DATE_TIME DISTINCT_PROVIDERS INCOMING OUTGOING TOTAL_PROCESS
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Just to add here is the Splunk documentation for transitioning from SQL to SPL: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 16:18:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456501#M56199</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-10-31T16:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456502#M56200</link>
      <description>&lt;P&gt;Hi Nilay, thanks for your quick response and the reference link form Sql to SPL.&lt;BR /&gt;
My source data is in Oracle. please don't let my screenshot of the excel mis-guide you. I used that to only show how i want my final visualization to look like in Splunk.&lt;BR /&gt;
The query is the one i am trying to translate into Splunk, so hard-coding the incomding, outgoing,, providers etc wont work. It has to be something that's generated dynamically.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 17:46:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456502#M56200</guid>
      <dc:creator>mnikhil7692</dc:creator>
      <dc:date>2018-10-31T17:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456503#M56201</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/146667"&gt;@mnikhil7692&lt;/a&gt; hardcoding was only to generate sample data as per your question as we will not have same data as your system. Please provide some sample events (mock/anonymize any sensitive information).&lt;/P&gt;

&lt;P&gt;Unless we know what your event looks like and what are your fields it will not be easy for us to assist, however, based on your query provided &lt;STRONG&gt;try the following and confirm&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="MyIndex" sourcetype="MySourceType" source="MySource" 
| eval _time=strptime(creation_date_time,"%m/%d/%Y")
| timechart count(eval(FLAG=="O")) as Outbound count(eval(FLAG=="I")) as Inbound dc(provider_name) as Providers
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR May be the following if you do not need Time as epoch time and your existing creation_date_time is in &lt;CODE&gt;MM/DD/YYYY&lt;/CODE&gt; format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="MyIndex" sourcetype="MySourceType" source="MySource" 
| chart count(eval(FLAG=="O")) as Outbound count(eval(FLAG=="I")) as Inbound dc(provider_name) as Providers by creation_date_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the run anywhere example based on cooked up data as per my understanding of your data. Each event has creation_date_time in MM/DD/YYYY format. FLAG O and I denote Outbound and Inbound respectively and provider_name can repeat, where you want unique provider count. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;PS: Intention of run anywhere search is to demo the required output. Instead of commands from | makeresults till | KV, you will use your main search using index="MyIndex" sourcetype="MySourceType" source="MySource", as mentioned above.&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval data="CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=O,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/24/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=X;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;CREATION_DATE_TIME=10/15/2018,FLAG=I,provider_name=Y;"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| KV
| eval _time=strptime(CREATION_DATE_TIME,"%m/%d/%Y")
| timechart count(eval(FLAG=="O")) as Outbound count(eval(FLAG=="I")) as Inbound dc(provider_name) as Providers
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:52:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456503#M56201</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T21:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456504#M56202</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt; , thanks for your reply. I did find my solution ; it was hiding all along in plain sight. Some of my fields were in lowercase i.e. dc(provider_name) instead of dc(PROVIDER_NAME).&lt;BR /&gt;
But all the info and the links you have provided is very useful, for someone who is starting off, like me. Cheers !&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:51:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456504#M56202</guid>
      <dc:creator>mnikhil7692</dc:creator>
      <dc:date>2020-09-29T21:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456505#M56203</link>
      <description>&lt;P&gt;@mnikhil7692, did you get a chance to try out the answer?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 04:46:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456505#M56203</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-11-06T04:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you translate SQL into Splunk?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456506#M56204</link>
      <description>&lt;P&gt;Hi Niket, i did. i replied back on the post that i found the solution.&lt;BR /&gt;
Thanks for all your help.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 11:50:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-do-you-translate-SQL-into-Splunk/m-p/456506#M56204</guid>
      <dc:creator>mnikhil7692</dc:creator>
      <dc:date>2018-11-06T11:50:05Z</dc:date>
    </item>
  </channel>
</rss>

