Write SQL query to create output dataset with quarterly exchange rate based on input table with exchange rate by monthly

Hi All,

Need to create the output dataset based on below input table. Could you please help.

My Input:

|from_currency|month|year| exchange_rate|



Need to write SQL query to create the above output table based on input dataset. The output dataset exchange rate is calculated based on sum of respected month values divided by 3.


SELECT from_currency
     , DATE_BUCKET(quarter, 1, DATEFROMPARTS(year, month, 1)) AS qtr
     , AVG(exchange_rate) AS avg_exchange_rate
GROUP BY from_currency
  , DATE_BUCKET(quarter, 1, DATEFROMPARTS(year, month, 1));

I getting error message - 'DATE_BUCKET' is not a recognized built-in function name.

I want to run the query in synapse analytics sql database

If you look at the dbfiddle link I sent, you'll see I included an example that works in SQL Server versions prior to 2022.

I don't know what functions are supported in Synapse, so you'll need to refer to the documentation if you want to adapt these methods.

Thank you so much and appreciate your help!