-1

I am trying to calculate average of P value in following table as per month in per_date column grouped by qu_def column.

enter image description here

and store it as follows in a SQL Server table:

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
V_immo
  • 31
  • 1
  • 7

1 Answers1

1

You seem to want a query like this:

select qu_def, for_cur,
       datefromparts(year(per_date), month(per_date), 1) as per_date,
       max(per_date) as date, avg(p) as p
from t
group by qu_def, for_cur,
       datefromparts(year(per_date), month(per_date), 1);

You can use INSERT to put this in an existing table or INTO to create a new table.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786