简体   繁体   中英

Calculate 3 month rolling avg grouped by person when there are multiple transactions per day per person

I need to query a table that has "Units" "Date" and "Name" and get the rolling average of units per month per person when there are multiple units per day per person on individual rows.

For example:

Name            Date        Units
John Smith      1-1-2022    1
John Smith      1-1-2022    1
Jane Smith      1-1-2022    1
Jane Smith      1-1-2022    1

The Unit count is ALWAYS 1 and there are multiple days per month. PLEASE HELP

If you want to average you can use the AVG which returns the average value.

Example query using AVG;

Select name, MonthName(date), AVG(Unit) as average from yourtable group by monthname(date), name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM