How do I segment by filtering in Database to query log_link_visit_action to matomo_segment

Hi Team,
This is crucial to us as we are scaling up - and to compare month over month data we want to move away from UI and use Database as a point of truth.
So we want to pull the data directly from database itself but unable to connect matomo_segments to log_link_action_visit - ideally we want HITS(calculated as GROUP BY idaction_url from log_link_visit_action) in connection to matomo_log_action(which we use to narrow down to specific feature) and in connection to matomo_segments (We divide end user organizations in this table and also to exclude end user from is a part of dimension).

Can you suggest a way forward? for this as this is crucial to us - ANY FORM OF GUIDANCE WILL HELP US!!
I have included the DB Schema as well just for the Dev. team who is looking into the message.

Thanks!
Mohnish