Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.
/ weighted_mean Public archive

A simple weighted mean aggregate function for postgresql

License

Notifications You must be signed in to change notification settings

Kozea/weighted_mean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weighted Mean extension for PostgreSQL

This extension provides a "weighted mean" aggregate function for postgreql.

The weighted mean is defined as a two columns aggregation function, one containing the measure to be averaged, the second containing the weight of each measure.

This extensions is implemented as a C library.

Installation

You can either install it with the pgxn client:

pgxn install weighted_mean

Or from source:

git clone git://github.com/Kozea/weighted_mean.git make && sudo make install

Then, create the extension in the specific database:

CREATE extension weighted_mean;

Usage

select weighted_mean(unitprice, quantity) from sales;

This is equivalent to:

select case when sum(quantity) = 0 then 0 else sum(unitprice * quantity) / sum(quantity) end from sales;

About

A simple weighted mean aggregate function for postgresql

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published