Hi,
There are multiple solutions you can use for the task. According to the tags which you used office-sharepoint-online
and azure-sql-database
I assume hat the best solution for you will; be using Azure Logic Apps.
You can schedule the execution using Recurrence trigger, execute query on the Azure Database and get the result using the SQL Server connector and the Execute a SQL query (V2)
action, use the SharePoint connector and the Create File action to create csv file
You can also Create Excel file instead of csv using the the excel connector (check this)