Splunk Search

How do I divide data in a field by a certain value?

BobKimata
Path Finder

I have a search based on an SQL query e.g. select * from . I would like to divide some data displayed on a field called 'Cost' by 2 and display result on the same field. I only have one row of data.

Thanks

Tags (1)
0 Karma
1 Solution

Flynt
Splunk Employee
Splunk Employee

add |eval Cost=Cost/2 after your SQL search

View solution in original post

Flynt
Splunk Employee
Splunk Employee

add |eval Cost=Cost/2 after your SQL search

BobKimata
Path Finder

I did that but receive this error:
command="dbquery", A database error occurred: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '|eval Cost=Cost/2' at line 1.

The sql query works fine without the expression.

0 Karma

Flynt
Splunk Employee
Splunk Employee

Can you give the whole syntax for your search? The |eval Cost=Cost/2 is a Splunk function and would need to exist outside of any dbquery commands.

0 Karma

BobKimata
Path Finder

I got it working. I had forgotten to put the SQL query in quotes. Thanks

0 Karma

Flynt
Splunk Employee
Splunk Employee

Excellent! Please accept if the answer was helpful.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...