stats command overview - Splunk Documentation (2024)

The SPL2 stats command calculates aggregate statistics, such as average, count, and sum, over the incoming search results set. This is similar to SQL aggregation.

If the stats command is used without a BY clause, only one row is returned, which is the aggregation over the entire incoming result set. If a BY clause is used, one row is returned for each distinct value in the field specified in the BY clause.

Syntax

The required syntax is in bold.

stats
[allnum = <boolean>] [delim = <"string">] [partitions = <num>]
<aggregation> ...
( [<by-clause>] [span=<time-span>] )

How the SPL2 stats command works

What's important to remember about the SPL2 stats command is that the command returns only the fields used in the aggregation.

Suppose these are some of the events in your dataset:

_timehostactionquantityproductIdmethod
6 Apr 2022 9:39:48.000 PMwww2purchase1PZ-SG-G05POST
6 Apr 2022 9:34:10.000 PMwww1view1GET
6 Apr 2022 9:34:02.000 PMwww3purchase2SC-MG-G10POST
6 Apr 2022 9:34:01.000 PMwww2remove1CU-PG-G06GET
6 Apr 2022 9:34:01.000 PMwww1purchase3POST
6 Apr 2022 9:29:55.000 PMwww3addtocart2SC-MG-G10GET
6 Apr 2022 9:20:51.000 PMwww1addtocartDB-SG-G01GET
6 Apr 2022 9:12:56.000 PMwww2changequantity2FS-SG-G03GET
6 Apr 2022 9:12:53.000 PMwww11DB-SG-G01GET

Using functions

You can use a wide range of statistical functions that you can use with the stats command. See Quick Reference for SPL2 Stats and Charting Functions.

The following search performs several aggregate calculations. When you perform more than one aggregation, separate each aggregation with a comma.

...| stats count(productId), sum(quantity), max(quantity), min(quantity)

The results look like this:

count(productId)sum(quantity)max(quantity)min(quantity)
71331

Grouping results

Use a BY clause when you want to group search results by a specific field.

The following search groups the results by the action field:

...| stats count(action) BY action

The results look like this:

actioncount(action)
addtocart2
changequantity1
purchase3
remove1
view1

You can perform an aggregation on one field and group the results by another field. The following search groups the results by the host field:

...| stats count(productId) BY host

The results look like this:

hostcount(productId)
www14
www23
www32

Renaming fields

Use the AS clause to rename a field. The following search renames the count(action) field to count:

...| stats count(action) AS count BY action

The results look like this:

actioncount
addtocart2
changequantity1
purchase3
remove1
view1

For additional examples, see stats command examples.

You can also use the from command to specify aggregate functions, group by a field, and rename a field. See stats command usage for examples.

See also

stats command
stats command syntax details
stats command usage
stats command examples
Functions
Overview of SPL2 stats functions
SPL2 Stats and Charting Functions Quick Reference
stats command overview - Splunk Documentation (2024)
Top Articles
Anniston Most Wanted
6 of the best alfresco restaurants in the world, from Miami to Tokyo
Netr Aerial Viewer
Craigslist Cars Augusta Ga
What Are the Best Cal State Schools? | BestColleges
Unitedhealthcare Hwp
What are Dietary Reference Intakes?
Teenbeautyfitness
Beds From Rent-A-Center
Cvs Devoted Catalog
U.S. Nuclear Weapons Complex: Y-12 and Oak Ridge National Laboratory…
Sport Clip Hours
Huge Boobs Images
Louisiana Sportsman Classifieds Guns
Divina Rapsing
50 Shades Of Grey Movie 123Movies
Energy Healing Conference Utah
FDA Approves Arcutis’ ZORYVE® (roflumilast) Topical Foam, 0.3% for the Treatment of Seborrheic Dermatitis in Individuals Aged 9 Years and Older - Arcutis Biotherapeutics
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Long Island Jobs Craigslist
Empire Visionworks The Crossings Clifton Park Photos
Why do rebates take so long to process?
Optum Urgent Care - Nutley Photos
Encyclopaedia Metallum - WikiMili, The Best Wikipedia Reader
Snohomish Hairmasters
Downtown Dispensary Promo Code
Tom Thumb Direct2Hr
Penn State Service Management
Tu Housing Portal
91 Octane Gas Prices Near Me
Mbi Auto Discount Code
Craigslist Gigs Norfolk
Max 80 Orl
John F Slater Funeral Home Brentwood
2008 Chevrolet Corvette for sale - Houston, TX - craigslist
State Legislatures Icivics Answer Key
Deshuesadero El Pulpo
Doordash Promo Code Generator
Lovely Nails Prices (2024) – Salon Rates
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
Atu Bookstore Ozark
Ups Authorized Shipping Provider Price Photos
Marcal Paper Products - Nassau Paper Company Ltd. -
40X100 Barndominium Floor Plans With Shop
Secrets Exposed: How to Test for Mold Exposure in Your Blood!
Meee Ruh
Dietary Extras Given Crossword Clue
Michaelangelo's Monkey Junction
15:30 Est
Congressional hopeful Aisha Mills sees district as an economical model
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Cbs Scores Mlb
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 6074

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.