It's not recommended to have an external writable interface with your database, but if you create a user that only has "SELECT" permissions to the database, the following might be usable:
(Nonetheless, you may paste this in the SQL Box interface of OTRS and get a result.)
Note that any external access to the database bypasses the front security provided by the OTRS interface and potentially compromises the confidentiality of the contents of the database. This is why GenericInterface and TicketSearch is recommended, as it is secured through the application.
Don't forget that there are reports/statistics available in OTRS that can pull this information via bin/
otrs.Console.pl Mint::Stats::Generate --number xxxxx