﻿---
title: ES|QL WEIGHTED_AVG function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/2988/reference/query-languages/esql/functions-operators/aggregation-functions/weighted_avg
products:
  - Elasticsearch
---

# ES|QL WEIGHTED_AVG function
## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/2988/reference/query-languages/esql/images/functions/weighted_avg.svg)


## Parameters

<definitions>
  <definition term="number">
    A numeric value.
  </definition>
  <definition term="weight">
    A numeric weight.
  </definition>
</definitions>


## Description

The weighted average of a numeric expression.

## Supported types


| number  | weight  | result |
|---------|---------|--------|
| double  | double  | double |
| double  | integer | double |
| double  | long    | double |
| integer | double  | double |
| integer | integer | double |
| integer | long    | double |
| long    | double  | double |
| long    | integer | double |
| long    | long    | double |


## Example

```esql
FROM employees
| STATS w_avg = WEIGHTED_AVG(salary, height) BY languages
| EVAL w_avg = ROUND(w_avg)
| KEEP w_avg, languages
| SORT languages
```


| w_avg:double | languages:integer |
|--------------|-------------------|
| 51464.0      | 1                 |
| 48477.0      | 2                 |
| 52379.0      | 3                 |
| 47990.0      | 4                 |
| 42119.0      | 5                 |
| 52142.0      | null              |