Hello @khachatur ,
Use this things which is looks same as you think.
Instead of SQL queries, you can make multiple views with different filters and sorting orders.
Then set automation with triggers like "When record enters view" OR "When the record is updated"
This step is considered as your SQL step.
Then track that record and use Automation with scripting step. Where you can use JavaScript code to calculate things and send data to perticular API(CRM).
This step is considered as your connection with CRM.
Notes:- You need to know JS for use Scripting Step. Scripting step has a limit of 30 seconds of execution it can perform only short term based operations. Make sure you don't do multiple loop at here.