[英]Calculate 3 month rolling avg grouped by person when there are multiple transactions per day per person
我需要查詢一個包含“單位”、“日期”和“姓名”的表,並在每人每天有多個單位的單獨行上獲取每個人每月單位的滾動平均值。
例如:
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
單位計數始終為 1,並且每個月有好幾天。 請幫忙
如果你想取平均值,你可以使用返回平均值的AVG 。
使用 AVG 的示例查詢;
Select name, MonthName(date), AVG(Unit) as average from yourtable group by monthname(date), name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.