Splunk Search

Multiple 'Where' conditions

sweety1309
Explorer

Hi I have the below query.But its output is "no results found".I dont know what mistake am I making.Please help

 

index="entab_due" Session=2019 ClassName="* *"
| join type=outer AdmissionNo, FeeInstallmentName, Session
[search index="entab_collection"]
| eval start = strptime(DueDate, "%d/%m/%Y")
| eval end = strptime(RecDate, "%d/%m/%Y")
| eval duration = round((end-start)/86400)
| where (duration > 45 and duration <= 75) AND (duration > 105 and duration <= 120) AND (duration > 120 and duration <= 180) AND (duration > 180)
| table AdmissionNo,StudentName

danspav
SplunkTrust
SplunkTrust

Hi @sweety1309 

I think the issue is with the where clause. 

Say the duration is 108.

The where clause will not match on:  (duration > 45 and duration <= 75)

But will match on:  (duration > 105 and duration <= 120)

However, the where clause uses AND between these terms, so the duration must be both less than 75 AND greater than 105.

Try replacing your ANDs with ORs:

| where (duration > 45 AND duration <= 75) OR (duration > 105 AND duration <= 120) OR (duration > 120 AND duration <= 180) OR (duration > 180)


Seeing as you don't use the duration field, you could simplify it further:

| where (duration > 45 AND duration <= 75) OR (duration > 105)

 

0 Karma

sweety1309
Explorer

I need common data which occurs in all the duration set thats why i m using AND here

0 Karma

renjith_nair
Legend

Possibly conditions in the where clause is negating each other.

What's your expected result?

---
What goes around comes around. If it helps, hit it with Karma 🙂

sweety1309
Explorer

I need all data which is available in all three durations set

0 Karma

renjith_nair
Legend

try OR instead of AND

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

sweety1309
Explorer

but OR will not give me the common data which occurs in all the duration set.I need common data

0 Karma

renjith_nair
Legend

As mentioned earlier, conditions are negating each other.

For e.g. take first and last condition

sample adata :

duration = 1, 2,55,160,180

condition:

where (duration > 45 and duration <= 75)

AND (duration > 180)

In the above case, first condition will result in 55 and will be negated by AND in the second condition which > 180. So you wont get any result

sample search

|makeresults|eval duration="1 2 55 160 180 200"|makemv duration|mvexpand duration
| where (duration > 45 and duration <= 75)
 OR (duration > 105 and duration <= 120) 
 OR (duration > 120 and duration <= 180) 
 OR (duration > 180)

If this is not your requirement, please provide sample input duration and expected output

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...